So for my 230 directories, I need to hand a certain number of those directories as an argument to cp. I decided to copy anything starting with a through i to one drive, j through r to another, and s through z to a third. From the source directory, you do this:
ls -d [a-i]* | xargs -J name cp -Rp name /path/to/backup/folder/
The -d flag is important, as that will make ls just return the name of the directory. The [a-i]* will match anything starting with a through i, followed by any number of characters. The -J lets you specify a replacement string. This takes the input supplied via the pipe, and for each line of input (in this case, the name of a directory), runs cp, replacing "name" with, in this case, the name of a folder.
And, of course, -Rp to recursively copy everything in those folders, preserving permissions, special attributes, ACLs, etc.
No comments:
Post a Comment