Yeah, this is simple but I’m forgetful so heres how you copy an entire directory, its subdirectories, and files:
cp -R dirtocopy/ newdir/
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 .
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.
This just helped me. Thanks!
Handy info. Thanks.
Handy info. Thanks
You were top on google.co.uk for “linux copy directory”
Just info I needed
“You were top on google.co.uk for “linux copy directory””
cp -a is better, as it preserves timestamps and symlinks. If you also want to preserve hardlinks, use cpio -p or rsync -H
Thank u very much
U kik ass
Thank you ^_^
Top of google, gave me what I needed!
Top of google! Thanks!
Awesome! Thanks much!
Thanks a lot man.. really helped me…
cp –reply=yes -r * folder2(path of folder you want to copy to)
Wow! Thanks dude! Amazing info! Top of google too! You rock!!
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: ‘.’)
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.
Thanks, this info helped.
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.
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).
@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
Ankush was accurate. The space and the dot at the end of what he typed was the destination directory, aka the current directory.
Thanks for the info!
Thanks for the info. thats helped me
I am glad that i could be at everyones help……the pleasure is all mine….:)
Will this also copy hidden sub folders?
thanx buddy…. ;P
Thanks, u have answered very precisely
You da man!!! Danka!
Truth machine, cp -a is an amazing cool command. thanks
Nice tip, thanks a bunch ^^ Gotta love googling for help when everything else fails :p
Well I’ll be, I search on the Google for this, and this website pops up first. Good job on that SEO