cp: Copy Files in UNIX & Linux

cp is a command to copy a file. Files can be copied either to the same directory or to a completely different directory, possibly on a different file system or hard disk drive. If the file is copied to the same directory, the new file must have a different name to the original; in all other cases, the new file may have the same or a different name. The original file remains unchanged.

• Copy a file to the current directory

# cp file file.bak

• Copy a file in the current directory into another directory

# cp myfile /oracle/home/siti

• Copy a file to a new file and preserve the modification date, time, and access control list associated with the source file

# cp -p yourfile yourfile.jr

• Copy all the files in a directory to another directory

cp /home/siti/favourite/* /home/dhiya/favourite/

• Copy a directory, including all its files and sub directories, to another directory

# cp -R /home/siti/favourite /root

You May Also Like

Leave a Reply?