Copy an Entire Directory in Linux
Linux November 4th, 2005Yeah, this is simple but I’m forgetful so heres how you copy an entire directory, its subdirectories, and files:
cp -R dirtocopy/ newdir/
Yeah, this is simple but I’m forgetful so heres how you copy an entire directory, its subdirectories, and files:
cp -R dirtocopy/ newdir/
June 23rd, 2006 at 1:19 pm
Here’s how to do the copy shown in the figure below. This copies the directory /home/jane, with all its files and subdirectories, and creates a subdirectory named jane in the current directory (.) :
cp -r /home/jane .
January 10th, 2007 at 3:01 pm
One thing missing, like it is mandatory to give the path name where u want to copy.If u keep blank, it will copy in the same directory.It will be
cp-rf present/directory /desire/directory
“f” parameter passed to do it “forcefully”.
Another command is, if u can’t remember the “r”[recursively] parameter then try with
cp present/directory/* /desire/derectory
Also keep in mind, in anycase, use the slash carefully.If u r in root mode then it might give u some pain.
January 20th, 2007 at 2:49 pm
This just helped me. Thanks!
January 21st, 2007 at 3:29 am
Handy info. Thanks.
March 22nd, 2007 at 11:38 pm
Handy info. Thanks
March 23rd, 2007 at 9:48 am
Thanks
You were top on google.co.uk for “linux copy directory”
Just info I needed
March 29th, 2007 at 11:13 am
Thanks
April 27th, 2007 at 5:45 am
“You were top on google.co.uk for “linux copy directory””
That’s sad.
cp -a is better, as it preserves timestamps and symlinks. If you also want to preserve hardlinks, use cpio -p or rsync -H
May 15th, 2007 at 10:28 am
Thanks!
June 11th, 2007 at 8:33 pm
Thank u very much
July 24th, 2007 at 10:37 am
Awesome Dude!
August 23rd, 2007 at 1:33 pm
U kik ass
September 23rd, 2007 at 2:27 am
Thank you ^_^
November 20th, 2007 at 5:27 am
Top of google, gave me what I needed!
November 29th, 2007 at 4:12 am
Top of google! Thanks!
December 29th, 2007 at 11:55 pm
Awesome! Thanks much!
January 8th, 2008 at 1:25 pm
Thanks a lot man.. really helped me…
January 9th, 2008 at 11:28 pm
cp –reply=yes -r * folder2(path of folder you want to copy to)
January 29th, 2008 at 3:22 pm
Wow! Thanks dude! Amazing info! Top of google too! You rock!!
February 6th, 2008 at 4:49 am
Spot on! Thanks heaps.
The definition in “man cp” is a bit confusing.
I mean, what’s ‘recursively’ meant to mean anyway?
PS: “cp -r sourcedir .” will copy ’sourcedir’ to the current directory (hence ‘.’) so if you want it put somewhere else you need to specify this instead of ‘.’
Also, remember that any path beginning with ‘/’ must start in the root directory (ie: “cp -r /folder” will copy the ‘folder’ directory from the root directory ‘/’), otherwise it must be in the current directory (ie: ‘.’)
February 21st, 2008 at 1:42 pm
I need help to!
i just need the files copied. no create a subdirectory.which
cp -r /dir1 /dir2 does. dir1 will be a sub in dir2 which I don’t need i just need the non-hidden files copied into dir2. I tried /dir1/*.*
it didn’ work.Please help.
February 24th, 2008 at 3:34 am
Thanks, this info helped.
@samjetski
In programming recursive means anything which calls itself. In this case you are telling cp to call ‘cp sourcepath/curdir/* destpath/curdir/’ on each directory.
March 6th, 2008 at 10:06 pm
Thanks, Dude. Saved me a trip to the man page
As others have said, you are the top result for googling “cp directories linux”. Pretty cool!
truth machine had a point, though: “cp -a” is the best method to recreate the directory structure on a new drive the way it is currently on an old drive (for example).
that said…
@tm: the -a argument is best for doing what I said above, but the way notsleepy suggested works for backups, or copying dirs that contain no symlinks
March 19th, 2008 at 8:22 pm
Handy info. Thanks
April 4th, 2008 at 12:22 pm
Ankush was accurate. The space and the dot at the end of what he typed was the destination directory, aka the current directory.
May 7th, 2008 at 3:32 pm
Thanks for the info!
May 26th, 2008 at 9:58 pm
Thanks for the info. thats helped me
July 20th, 2008 at 1:02 am
I am glad that i could be at everyones help……the pleasure is all mine….:)
August 9th, 2008 at 2:51 am
Will this also copy hidden sub folders?
September 6th, 2008 at 9:19 am
thanx buddy…. ;P