Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would be happy if someone can bring an example syntax for the problem above.

Thank you in advance.

share|improve this question
   
love your humor :) – user8290 Dec 11 '11 at 3:01
1  
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
1  
@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

3 Answers

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
1  
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

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

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

Your Answer

 
discard

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.