Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to copy the contents of a folder to another folder in a different directory using terminal.

Would somebody be able to provide me an example of the command line syntax required to achieve this?

share|improve this question
love your humor :) –  user8290 Dec 11 '11 at 3:01
tried to be specific and clear :) –  pandisvezia Dec 11 '11 at 16:01
Oh, I am so sorry: I misunderstood and thought it was asked by Bruno! Apologies. –  user8290 Dec 11 '11 at 16:08
ahahahaha you're welcome –  pandisvezia Dec 11 '11 at 16:28
@Christopher the shame! (no, honestly, no question is so silly that does not need to be asked at least one time;)) –  Bruno Pereira Dec 11 '11 at 18:15

4 Answers 4

You can copy the content of a folder /source to another existing folder /dest with the command

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.

share|improve this answer
Thank you enzotib! It seems another useful syntax for copy operations. –  pandisvezia Dec 11 '11 at 15:52
Great answer. I will write a real example in case someone is having trouble with this command: sudo cp -a /var/www/opencart/. /var/www/opencart_local/ –  pablofiumara Nov 11 '13 at 15:29
@enzotib I am trying to use this command to copy the contents of "Downloads/textext" to "~/.config/inkscape/extensions/." Using your command I type "cp -a /Downloads/textext/. /~/.config/inkscape/extensions/." but this does not work –  Funzies Feb 5 '14 at 11:09
@Funzies: probably your command should be: cp -a ~/Downloads/textext/. ~/.config/inkscape/extensions/ –  enzotib Feb 6 '14 at 7:58
Great answer @enzotib! I wish I knew this before. :-) –  fmquaglia Nov 19 '14 at 17:26

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.

share|improve this answer
Thank you for the alternative! –  pandisvezia Dec 11 '11 at 15:58
thank you very much!! –  thecodeparadox Nov 1 '12 at 15:39

Lets say you have a folder called folder1 in your ~, inside folder1 is 1 file called file1 and 2 folders called sub1 and sub2 each with other files and folders inside them.

To copy all the contents of ~/folder1 to ~/new_folder1 you would use

cp -r ~/folder1/. ~/new_folder1

new_folder1 would then contain all the files and folders from folder1.

cp is the command to copy using a terminal, -r makes it recursively (so, current directory + further directories inside current) ~/folder1 is the origin folder, ~/new_folder1 is the destination folder for the files/folders inside the origin.

share|improve this answer
it does not catch hidden files –  Portablejim Dec 11 '11 at 13:04
Fixed, should work now. –  Bruno Pereira Dec 11 '11 at 14:10
Thank you Bruno! It helped me to understand the syntax, though I had to change it a bit(removing ~ sign). Maybe because the destination folder was in /opt, which resides in another file system. And thank you Portablejim to remember the hidden file thing! –  pandisvezia Dec 11 '11 at 15:51
The trailing period is important. Without it, sometimes it may create a new subdirectory ~/new_folder1/folder1 instead of copying the contents over. –  wisbucky Jan 19 at 23:00

Check this http://www.cyberciti.biz/faq/copy-folder-linux-command-line/ for more information on copying folder. Hope this helps.

cp Command

cp is a Linux command for copying files and directories. The syntax is as follows:

cp source destination
cp dir1 dir2
cp -option  source destination
cp -option1 -option2  source destination

In this example copy /home/vivek/letters folder and all its files to /usb/backup directory:

cp -avr /home/vivek/letters /usb/backup


-a : Preserve the specified attributes such as directory an file mode, ownership, timestamps, if possible additional attributes: context, links, xattr, all.

-v : Explain what is being done.

-r : Copy directories recursively. Example

Copy a folder called /tmp/conf to /tmp/backup:

$ cp -avr /tmp/conf/ /tmp/backup
share|improve this answer
thank you so much @guntbert for telling y you gave negative. I have updated my answer. Thanks again.. –  Dilip Rajkumar Nov 27 '14 at 11:44
This isn't what the question asks. –  cybermonkey Mar 8 at 13:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.