Solaris copy files from multiple directories into a single directory

653 views Asked by At

I have a need to regularly copy files from a specific set of source sub directories (100's of them) into a 'flat" directory structure, i.e. i want all the files from the multiple source directories in a single destination directory. I can't seem to find a way of copying that can look into the source sub directories & copy the files that doesn't re-create the sub-directory folder structure in the destination directory.

Any help appreciated.

1

There are 1 answers

2
Guntram Blohm On
sourcedir=/root/of/subdirectory/set
destdir=/where/the/files/go

find $sourcedir -type f -print | while read file; do cp $file $destdir; done

or (prevent overwrites)

find $sourcedir -type f -print | while read file; do base=$(basename $file); test -f $destdir/$base || cp $file $destdir; done

Note this will not work if any of the names of the files or subdirectories in $sourcedir contain spaces.