Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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 has more clear information. – Dilip Rajkumar Nov 25 '14 at 5:52
Why you haven't accepted an answer? – gsamaras Jul 19 at 20:14

5 Answers 5

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

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

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
@DylanValade: -a already implies --preserve=all, that is wider than -p = --preserve=mode,ownership,timestamps. – enzotib Dec 22 '14 at 16:22

Check this 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

If there are two folders: (with write permission)

drwxr-xr-x 4 vimal vimal  4096 Sep  9 12:17 .
drwxr-xr-x 3 root  root   4096 Aug 18 14:35 ..
drwxrwxrwx 6 vimal vimal  4096 Sep  9 12:15 DATA
drwxrwxrwx 7 vimal vimal  4096 Sep  9 12:15 PORTAL

If you are inside the folder called PORTAL where you want to copy all content of another folder say DATA at the same level then you will do

vimal@vimal-D3H:/var/www/html/PORTAL$ cp -a ../DATA/. .

You have to notice 2 dots. Last dot says copy here in present folder


one following /DATA/. says that all the CONTENTS inside DATA folder to be copied, and not the DATA folder itself.

If you remove this trailing "." from /DATA/

then whole DATA folder will be copied inside PORTAL(from where you are coping).

share|improve this answer

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.