I needed to be able to exclude files with a certain extension from a cp command that was going to be executed automatically as part of a much larger script.
There doesn't seem to be any direct way to do this (e.g. cp --exclude...) and although there are several suggestions on the net on how to overcome this I found the neatest way was to use the tar command instead:
cd /copy/from/path
tar -czf /path/to/archive.tar.gz ./ --exclude=*.txt
cd /copy/to/path
tar -xzvf /path/to/archive.tar.gz
tar -czf /path/to/archive.tar.gz ./ --exclude=*.txt
cd /copy/to/path
tar -xzvf /path/to/archive.tar.gz
Of course this isn't ideal, creating a tar archive when it isn't necessary but the files I needed to copy weren't large and so it was nice and quick and dirty.
1 comment:
another solution using tar (it's a single command):
tar -C sourcedir --exclude=".svn" -cf - . | tar -C targetdir -xpf -
Post a Comment