cp
cp linux command cheatsheet by Thamizhiniyan C S
Last updated
cp linux command cheatsheet by Thamizhiniyan C S
Last updated
Command | Description |
---|---|
-a, --archive
Preserve the source's metadata, such as creation date, permissions, and extended attributes.
-b, --backup
Create backups for destination files. The backup file has the (~) suffix unless --suffix is used.
-f, --force
If the destination file/directory already exists, replace it with the source.
-i, --interactive
Ask before overwriting the destination with the source.
-l, --link
Create hard links instead of new files. The destination file will have the same inode attribute as the source.
-n, --no-clobber
Do not overwrite the destination file if it exists.
-R, -r, --recursive
Copy the source directory recursively.
-S, --suffix=
Provide a custom suffix for the backup file.
-t, --target-directory=
Specify a directory for the source files.
-u, --update
Replace files only if they satisfy the update condition. The short option replaces files if the destination is older than the source. The long option lets the user specify the condition (all, none, or older).
-v, --verbose
Output information about the copying process.
-p
Preserves file characteristics (modification time, access time, ownership, permission-bits).
*
Uses the * wildcard to represent all files and directories matching a pattern.
--help
Show help.
--version
Show version information.
Copy file-1.txt, file-2.txt, and file-3.txt to the test-dir directory.
Copy all files starting with file- to test-dir using the * wildcard.
Copy file-1.txt to test-dir with verbose output. Prompt to overwrite if the file exists.
Copy file-1.txt to test-dir, creating a backup file with .bak extension. Show verbose output.
Copy contents of Src_file to Dest_file. Overwrites Dest_file if it exists.
Copy contents of a.txt to b.txt. Overwrites b.txt if it exists.
Copy contents of a.txt to c.txt. Overwrites c.txt if it exists.
Copy Src_file1, Src_file2, and Src_file3 to Dest_directory. Overwrites existing files in Dest_directory.
Copy a.txt, b.txt, and c.txt to new/ directory. Overwrites existing files in new/.
Recursively copy all files from Src_directory to Dest_directory.
Interactive copying: prompts before overwriting Destination_file. Press 'y' to confirm overwrite.
Interactive copy of a.txt to b.txt. Prompts to confirm overwrite of b.txt.
Force copying: deletes Destination_file if unable to write, then copies Source_file.
Forceful copy of a.txt to b.txt. Overwrites b.txt without prompting.
Recursive copy of Directory_name1 contents to Directory_name2.
Recursively copy contents of source_directory to dest_directory.
Preserve copying: retains original file characteristics (timestamps, ownership, permissions) in Destination_file.
Preserves characteristics of a.txt when copying to c.txt.
Copy all .txt files to Destination Directory or file using * wildcard.
Copy all .txt files to Folder1 using * wildcard.