I want to copy a directory from one place to another folder.
sudo cp is the command, but after that what should I type? The destination or source first?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
-a flag is probably what you are looking for:
cp -a /path/from /path/to
-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.
You should only need to use
sudo if you are copying to a location not owned by the current user, if the current user doesn't have read permissions for the files being copied, or if you want to preserve ownership on files not owned by the current user.
If you want to copy directory please use below command:
sudo cp -R Source_Folder Destination_Folder
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.)
One more example:
sudo cp -R /var/www/* /home/test_user/
Please feel free to leave a comment in case of any issue.
For copy folder via terminal, you can use:
cp -a /source/. /dest/
-a option is an improved recursive option. It preserves all file attributes and also preserves symlinks.
. at the end of the source path is a specific cp syntax that allows copying all files and folders, including hidden ones.
An alternative is
rsync -r source/ destination