Copy (cp) shell command examples.

# Create a copy of a file:
cp ~/Desktop/foo.txt ~/Downloads/foo.txt

# Create a copy of a directory:
cp -r ~/Desktop/cruise_pics/ ~/Pictures/

# Create a copy but ask to overwrite if the destination file already exists
cp -i ~/Desktop/foo.txt ~/Documents/foo.txt


# To copy file1 to file2:
cp file1 file2

# To copy file1 into directory:
cp file1 directory

# To copy files into directory:
cp file1 file2 file3 ... directory

# To copy dir1 into dir2 including subdirectries:
cp -R dir1 dir2/

# To copy directory, preserving permissions:
cp -pR dir1 dir2/

##
# Copy a directory with all files and subdirectories
##
src=/home/$USER         # source
dst=/tmp/backup         # destination
cd "$src"
find . -print | cpio -pdmv "$dst"

# This method can be used to receate a directory hierarchy, without files, too:
find . -type d -print | cpio -pdmv "$dst"

# Copying across a network, this is an indispensable technique:
cd /the/source
tar cf - dir1 dir2 | ssh user@host "cd /the/dest && tar xvf -"