$ sudo cp -R Source_Folder Destination_Folder
$ sudo cp -R /media/mydrive/Movies /media/backup
This command can also be used to copy files, by just removing the “-R” which is used to copy the recursive structure of internal folders (if there are any in the Source_Folder path that we mentioned.)
The -a flag turns on recursive behaviour (which can also be done with the -R flag), and will also attempt to preserve metadata such as file ownership, permissions, timestamps, links, etc.
cp -a /source/. /dest/
The -a option is an improved recursive option, that preserve all file attributes, and also preserve symlinks.
The . at end of the source path is a specific cp syntax that allow to copy all files and folders, included hidden ones.
An alternate is rsync
rsync -r source/ destination
The advantages of rsync are:
- After the initial sync, it will then copy only the files that have changed.
- You can use it over a network, convenient for files in $HOME, especially config files.