Reputation: 131
The script does a simple operation of copying all files (excluding ".log" files) and all sub-directories into destination folder. The issue I am running into is the files that reside in sub-directories are also being copied into the destination folder so the end result is that those files show up twice; in the destination folder and also the sub folders of that folder. How can this be avoided? Thanks
source_dir="path/to/source"
dest_dir="path/to/destination"
arg=${1}
echo $arg
if [[ ! -d $dest_dir ]]; then
echo "creating destination directory $dest_dir"
mkdir $dest_dir
fi
#copy all files that don't end with .log
for resource in `find $source_dir ! -name '*.log'`; do
echo "copying resource $resource..."
cp -r $resource $dest_dir
done
Upvotes: 0
Views: 174
Reputation: 60275
I don't think rsync has a recursion limiter, and for something like this it's probably overkill anyway.
(cd /path/to/source; find -maxdepth 1 ! -name \*.log | cpio -pdv /path/to/destination)
Upvotes: 1