16

Due to a Hard disk problem I am trying to shift a partition from one hard disk to another. I am following http://www.ibm.com/developerworks/library/l-partplan.html article to do that. In the copying part I would like to ignore one particular sub directory. How can I accomplish that keeping in mind when copying I have to preserve my owner group and time stamp. There is around 700 GB of data that needs to be copied if I do not ignore a particular subdirectory.

0

8 Answers 8

21

rsync -ax --exclude [relative path to directory to exclude] /path/from /path/to

You might want (or not) to use --del as well. Check the manual page.

1
  • Yes that did the trick. This works..
    – P Roy
    Jun 13, 2010 at 9:32
2

Normally I use cpio as follows,

cd source_dir; find . -depth | cpio -pdmv dest_dir

And since this is a pipeline you can put a "subtraction filter" in the middle.

cd sourcedir; find . -depth | grep -v exclude_dir | cpio -pdmv dest_dir

or you could split this is into several steps,

cd source_dir; find . -depth > files.lst
gedit files.lst  # (take out the offending directory and files and save back to files.lst)
cpio -pdmv dest_dir < files.lst

Of course I'd test this on something smaller first but you get the idea.

0

You could write a simple bash script with a loop to ignore the certain path you don't want copied and copy the rest. Another solution could be to us regular expressions. You can read up on bash scripting here -> http://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html Regex tutorial here -> http://www.regular-expressions.info/

0

Can you temporarily move (mv) the large subdirectory to some other location, do the copy, and then restore the subdirectory? I can't see a direct option in cp to do this.

4
  • I too checked man cp there is no way to ignore using cp. I have 550 GB of data in that sub directory and mv that might take hours.
    – P Roy
    Jun 13, 2010 at 8:14
  • I assumed mv would be a relatively low-cost operation - updating references to the data rather than physically moving it around on the disk. At least, I've always found moves in Windows to be way quicker than copies - the Linux file system could work entirely differently.
    – Ash
    Jun 13, 2010 at 8:50
  • mv to the same hard disk is fast. But when one does a mv across hardisks I think it takes the same time as a cp.
    – P Roy
    Jun 13, 2010 at 10:56
  • I meant to move it somewhere on the same hard disk to get it out of the way, then copy the remaining to the remote disk, then move the big file back. Unless you're copying the entire disk from /.
    – Ash
    Jun 14, 2010 at 0:21
0

Rather ugly solution but... why not just cp everything in the directory non recursively, and then copy the individual directories over recursively?

0

how about using ls -a to get a list of everything in the directory you want to back up, and, (check your man pages to see if this is supported), using

cp -a {[comma separated list of folders and files you want to back up]} [backup directory].

0

Instead of rsync, which not always awailable, I can suggest to use tar

tar -cpP --exclude=.git --exclude=.cache -C "$source_dir" . | tar -xpP -C "$target_dir"

here you pack your directory to stdout and unpack it from stdin, it shall be faster than rsync because not need to count checksumms, it is memory efficient, because it is stream non packed archive.

-3

So why not just

cp -Rv [SRC] [DEST] | grep -v [EXCLUDE]
1
  • This will merely exclude the output lines from the verbose flag (-v) to cp from showing up in stdout. The EXCLUDE will still be copied from SRC to DEST. Apr 16, 2022 at 0:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .