Victus Spiritus

home

Carry only what is essential, Exceptional Copying

19 Jun 2011

Copying with excluded files and directories on Windows

xcopy /S /E source destination /EXCLUDE:ExcludeFile.txt

Copying with excluded files and directories on Linux, Mac OS X, or *nix

tar works well for the task at hand

tar -X exclude_file.txt -cvf - source | tar xvf - -C dest

rsync also has exclusion functionality built in:

rsync -r -t -v -b /source_folder /destination_folder

with additional args

--exclude 'bad_directory'

or

--exclude-from '/home/backup/exclude.txt'

(the exclude.txt file)

path/to/BIGdir
monkies.*

And cp with find, the superuser source of some of these commands. I didn't spend too much time with the last one but it was hiccuping on OS X with directory copying.

find ./source -not \( -name exclude_1 exclude 2 \) -print0 | xargs -0 -IFILES cp FILES ./destination

I tried a variant of this command and while it copied directories, it also copied their contents into the top directory at the destination destination.

find ./source -mindepth 1 -not \( -name exclude_1 exclude_2 -prune \) | xargs -Iitem cp -r item destination