Recursively find and copy a particular file to a different directory
I recently wanted to sync my .gitignore
files across two directories. I think rsync
should be able to handle this, but I wanted to have more control on the process and decided to write a shell script.
The below shell script worked worked great! Replace SOURCE_DIR
and DEST_DIR
with the absolute directory path.
#!/bin/bash
cd "SOURCE_DIR"
for f in $(find . -name ".gitignore"); do
echo $f
cp $f "DEST_DIR/$f"
done