• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

*nix Question - How Do I Copy Entire Directory?

Superwormy

Golden Member
I know I can copy files with ' cp file1 file2 /directory/to/copy/to/

But how can I copy an entire directory and all its contents?


Also, how can I delete an entire directory and its contents? It always tell me ' Directory Is Not Empty ' is there a way to override that?


Using FreeBSD btw...
 
man rm
man cp

rm -r will remove a directory and everything in it.
cp -r will copy recursively.

man is your friend.
 
If you want to make sure your doing a "duplication" with keeping permissions, ownership, and softlinks intact etc all correctly..

Do this:

cd /<source_directory>
find . -print | cpio -pdvm /<dest_dir>


Example: I want to copy /usr/src to /usr/local/src

cd /usr/src
find . -print | cpio -pdvm /usr/local/src



This is one of the best ways to copy an entire directory tree and ensure that you get an exact duplicate.
 
Originally posted by: Electrode
wow, you people sure make it sound complicated

cp -pr source destination

Yeah, no kidding. This version is perfectly fine. If you want to be really safe, use -pR instead of -pr, though in most cases this makes no difference.
 
Or if you have a LOT of data that you are copying across to a different hard drive use this:

tar cf - /<copy dir> | ( cd /<dest dir>; tar xf - )

At least I think I have that command correct 🙂 Basically this compresses the data before sending it across the IDE/SCSI bus, as well as preserves the file permissions, and then uncompresses it at the destination.


hehehe...as for *nix, there is always "more then one way to skin a cat", or in this case copy a directory 🙂
 
um, Fallen Kell? Wouldn't that still have to send the info over the IDE/SCSI bus? Since compression is done by the proc, not the HDD?
 
Originally posted by: BingBongWongFooey
haha you're still making it too complicated.

cp -a foo/ bar/

Doesn't work on alot of *NIX's, IIRC correctly FreeBSD is one of the *NIX's it doesn't work on.
 
DaHitman or Fallen Kell's way is the most fool-proof because it handles permissions and special files (/dev/ entries, symlinks, pipes, etc) correctly.
 
Originally posted by: Nothinman
DaHitman or Fallen Kell's way is the most fool-proof because it handles permissions and special files (/dev/ entries, symlinks, pipes, etc) correctly.

as does cp -pR
 
Back
Top