ADVERTISEMENT

Linux Commands ❯ cp

cp

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
syntax:

cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
  • cp my_file1 my_file2
    copy my_file1 as my_file2. if my_file2 already exists , it will be overwritten.
  • cp -f my_file1 my_file2
    copy my_file1 as my_file2. any existing file called my_file2 will be overwritten without any prompting.
  • cp -i my_file1 my_file2
    copy my_file1 as my_file2. if my_file2 already exists , there will be a prompt before overwriting the file.
  • cp -l my_file1 my_file2
    create a hard link of my_file1 as my_file2
  • cp -n my_file1 my_file2
    copy my_file1 as my_file2.The file will not be copied if my_file2 already exists.
  • cp -p my_file1 my_file2
    copy my_file1 as my_file2 along with the attributes such as time stamp, mode etc.
  • cp -r my_dir1 home_dir1
    recursively copy my_dir1 and all files and directories under that to the home_dir1
  • cp -R my_dir1 home_dir2
    recursively copy my_dir1 and all files and directories under that to the home_dir2
  • cp -s my_file1 my_file2
    create a symbolic link of my_file1 as my_file2
  • cp -u my_file1 my_file2
    copy my_file1 as my_file2 if my_file2 not exists already. update the contents of my_file2 with my_file1 if the latter is newer than my_file2