How To Copy Files From One Directory To Another In Ubuntu

http://askubuntu.com/questions/80065/i-want-to-copy-a-directory-from-one-place-to-another-via-the-command-line

http://askubuntu.com/questions/86822/how-can-i-copy-the-contents-of-a-folder-to-another-folder-in-a-different-directo

$ sudo cp -R Source_Folder Destination_Folder

example:

$ 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:

  1. After the initial sync, it will then copy only the files that have changed.
  2. You can use it over a network, convenient for files in $HOME, especially config files.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.