Mac-terminal.com

Mac-Terminal.com

An introduction of the Terminal for Mac OS X

cp

Syntax: cp [-Options] <source(s)> <target>

Usage/Result: Copy one or more file(s)/folder(s) to another location.

Options:

-RRecursive - Copy the folder and eventual files and subtrees inside this folder
-HSymbolic links on the command line are followed.
-LThe files and folders located in a symbolic link's destination is also copied.
-PNo files and folders from symbolic links are copied (This is the default action unless you say otherwise).
-fOverwrite every file or folder that already exists.
-iConfirm every action that will overwrite a current file or folder
-nDon't overwrite existing files.
-pPreserve attributes on the file(s)/folder(s) that you're copying (modification time, access time, file flags, file mode etc.)

Example

cp old.txt new.txtCopies the file old.txt in the current working directory to new.txt (new.txt will end up in the same directory).
cp old.txt ~/DocumentsCopies the file old.txt in the current working directory to the folder ~/Documents.
cp *.jpg ~/DocumentsCopies all jpg images in the current working directory to ~/Documents.
cp  -R Documents "Documents backup"Copies the folder Documents and all of it's content to the directory named Documents backup.

Quick tip: Sometimes you might not be able to perform a certain command or task from the Terminal. This might be because you don't have the right permission to do so. When that happens you can try to add the word "sudo" in the beginning of the line.
Sudo is an abbreviation of superuser do and means that you want to execute the following command as a user with extended permissions, most often as an Administrator. When using "sudo" you sometimes need to enter the password of the root account.
Learn more about sudo.