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.
8 Answers
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.
- 953
- 346
-
Yes that did the trick. This works.. – P Roy Jun 13 '10 at 09:32
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.
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/
- 1,046
- 2
- 16
- 32
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.
- 3,014
-
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 '10 at 08: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 '10 at 08: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 '10 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 '10 at 00:21
Rather ugly solution but... why not just cp everything in the directory non recursively, and then copy the individual directories over recursively?
- 129,178
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].
- 3,499
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.
- 602
- 1
- 7
- 15
So why not just
cp -Rv [SRC] [DEST] | grep -v [EXCLUDE]
-
This will merely exclude the output lines from the verbose flag (
-v) tocpfrom showing up in stdout. TheEXCLUDEwill still be copied fromSRCtoDEST. – Preston Maness Apr 16 '22 at 00:30