3

I am trying to copy all the *.psd files, currently in a multi directories structure, into one single directory. Is there an rsync parametrization to allow it?

The solution proposed at Copying files from multiple directories into a single destination directory is not a multilevel recursive directories, only single level subdirectories.

In my current case I have files in multiple recursive directories (up to 7 levels) that I would like to reconcile in a single directory.

Charles Mosndup
  • 600
  • 6
  • 19
  • Possible duplicate of [Copying files from multiple directories into a single destination directory](https://stackoverflow.com/questions/44460177/copying-files-from-multiple-directories-into-a-single-destination-directory) – TheNavigat Apr 29 '19 at 11:21

2 Answers2

4

I fear rsync can't help you here. You can use find to find all the files and copy them to the destination directory, though:

find /path/to/source/topdir -type f -name '*.psd' -exec cp {} /path/to/destination/ \;
choroba
  • 231,213
  • 25
  • 204
  • 289
3

In my opinion @choroba's answer is the right one.

For completeness (or if for any reason you needed the files to be copied with rsync) you can do something way less efficient using rsync (which is just like using cp in this case), using find, a loop and other things not really necessary.

for file in $(find ./path/to/source/topdir -name "*psd" ); do rsync $file /path/to/destination/; done
myradio
  • 1,703
  • 1
  • 15
  • 25