|
cp
Copy files.
SYNTAX cp [options] source_file target_file cp [options] source_file(s) target_folder Recursive_Options -R Copy the folder and subtree. Symbolic links will be copied not indirected through. cp will create special files rather than copy them as normal files. Created folders have the same mode as the corre- sponding source folder, unmodified by the process' umask. -H Symbolic links on the command line are followed. (Symbolic links encountered in the tree traversal are not followed.) -L All symbolic links are followed. -P No symbolic links are followed. This is the default. Other_Options -f For each existing destination pathname, remove it and create a new file, without prompting for confirmation regardless of its permis- sions. (The -f option overrides any previous -i or -n options.) -i Cause cp to write a prompt to the standard error output before copying a file that would overwrite an existing file. If the response from the standard input begins with the character `y' or `Y', the file copy is attempted. (The -i option overrides any pre- vious -f or -n options.) -n Do not overwrite an existing file. (The -n option overrides any previous -f or -i options.) -p Cause cp to preserve in the copy as many of the modification time, access time, file flags, file mode, user ID, and group ID as allowed by permissions. If the user ID and group ID cannot be preserved, no error message is displayed and the exit value is not altered. If the source file has its set user ID bit on and the user ID can- not be preserved, the set user ID bit is not preserved in the copy's permissions. If the source file has its set group ID bit on and the group ID cannot be preserved, the set group ID bit is not preserved in the copy's permissions. If the source file has both its set user ID and set group ID bits on, and either the user ID or group ID cannot be preserved, neither the set user ID nor set group ID bits are preserved in the copy's permissions. -v Verbose - show files as they are copied.
cp copies hard linked files as separate files. If you need to
preserve hard links, consider using tar(1), cpio(1), or pax(1) instead.
cp does not preserve Apple resource forks - use the ditto command for this.
EXAMPLES copy a file in the current folder cp old.txt new.txt copy a file in the current folder to your 'Documents' folder cp old.txt ~/Documents copy the file to the 'Documents' folder and rename the copy "new.txt" cp old.txt ~/Documents/new.txt copy all .jpg files to the Documents folder cp *.jpg ~/Documents copy the "Documents" folder to "Documents backup". The quotes are needed because of the space in the folder name. cp -R Documents "Documents backup" copy the entire /Users folder (including subfolders), preserving file ownership and permissions but not resource forks. Root access is required to use -p, so the example uses sudo to get root access temporarily. sudo cp -Rp /Users "/Users backup"
The white man knows how to make everything but he does not know how to distribute it - Sitting Bull
Related commands:
CpMac - Copy a file while preserving metadata and forks (Developer Tools)
dd - Data Dump - convert and copy a file (use for RAW
storage)
ditto - copy files and folders (Can preserve Apple
resource forks, type&creator)
copy - Copy groups of files in folders
install - Copy files and set attributes
mv - Move or rename files or directories
tar - store or extract files to an archive (allows symbolic
links to be copied as links)
umask - Users file creation mask
Equivalent BASH command:
cp - Copy Files