Manage files and folders
- cd - change directory
- ls - list the content of a directory
- pwd - parent working dir
- mkdir - create a new directory
- rm - Remove files and folders
- cp - Copy files and folders
- mv - Move files and folders
- ditto - Move files and folders (advanced)
Acess and permission to files/folders
cp
Syntax: cp [-Options] <source(s)> <target>
Usage/Result: Copy one or more file(s)/folder(s) to another location.
Options:
| -R | Recursive - Copy the folder and eventual files and subtrees inside this folder |
| -H | Symbolic links on the command line are followed. |
| -L | The files and folders located in a symbolic link's destination is also copied. |
| -P | No files and folders from symbolic links are copied (This is the default action unless you say otherwise). |
| -f | Overwrite every file or folder that already exists. |
| -i | Confirm every action that will overwrite a current file or folder |
| -n | Don't overwrite existing files. |
| -p | Preserve 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.txt | Copies the file old.txt in the current working directory to new.txt (new.txt will end up in the same directory). |
| cp old.txt ~/Documents | Copies the file old.txt in the current working directory to the folder ~/Documents. |
| cp *.jpg ~/Documents | Copies 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.