Copy a Directory from Command Line
Copying a directory for the sake of backup is something I do often, especially when I'm trying to figure out why something isn't working when I use an external library. I'll copy the directory structure as a backup, mess around with the original source until I find a solution, then restore the original and change my overall system code to bring in my revised version.
You can't just use cp
to copy a directory structure -- you'll see cp: myDir is a directory (not copied).
You'll need to add a few additional flags to copy a directory structure:
cp -Rp source source_copy
The above command copies the directory recursively while keeping the same permissions!
In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...
One of my favorite social APIs was the Open Graph API adopted by Facebook. Adding just a few META tags to each page allowed links to my article to be styled and presented the way I wanted them to, giving me a bit of control...
One of the more popular and simple effects I've featured on this blog over the past year has been linking nudging. I've created this effect with three flavors of JavaScript: MooTools, jQuery, and even the Dojo Toolkit. Luckily CSS3 (almost) allows us to ditch...
I was inspired when I first saw Addy Osmani's original ShineTime blog post. The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
Why do you have the
-s
flag in there? Looking at the--help
forcp
, that’s the option to “make symbolic links instead of copying”, and according to Stack Overflow http://stackoverflow.com/questions/1240636 , that doesn’t even work recursively (with the-R
flag). (Nor can I see why you would want to copy an entire directory recursively only for it to be populated with symlinks, especially “for the sake of backup”.) Typo?EDIT: David has since corrected the error in question.
Another great option that I somehow always forget to use is -a (archive), used like so:
It copies structure and permissions and also preserves symlinks.
Just use rsync, faster and more options. )
Good to know. But I agree with @John
I prefer to use rsync for this purpose