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!
![Create Spinning Rays with CSS3: Revisited]()
![Being a Dev Dad]()
I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...
![Send Email Notifications for Broken Images Using jQuery AJAX]()
It's usually best to repair broken image paths as soon as possible because they can damage a website's credibility. And even worse is having a user tell you about it. Using jQuery and PHP, you can have your page automatically notify you of broken...
![Introducing MooTools ScrollSidebar]()
How many times are you putting together a HTML navigation block or utility block of elements that you wish could be seen everywhere on a page? I've created a solution that will seamlessly allow you to do so: ScrollSidebar. ScrollSidebar allows you...
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