Have you ever wanted to copy all files of a certain type from a large directory tree to an identical directory tree?
For example, one time I needed to copy all the .so files from /var/lib/gems to the vendor directory because for some reason, dependencies didn't. Copying all files didn't appeal to me, so I made this script.
Example (greyed out directory entries for easier viewing):
$ du -a /source/path
$ copy-files-matching-pattern-preserving-path /source/path "*.txt" /destination/path Copying *.txt from /source/path to /destination/path...
/source/path/dir/another/directory/or/two/3.txt ==> /destination/path/dir/another/directory/or/two/3.txt
/source/path/dir/2.txt ==> /destination/path/dir/2.txt
/source/path/1.txt ==> /destination/path/1.txt
$ du -a /destination/path
It's basically a bash script for copying all files in a directory tree matching one or more specified patterns (such as *.txt) to another tree, creating any directories not already existing. It copies only the path below the source directory to the destination, and only creates directories with files matching the pattern.