Charles Mosndup
Charles Mosndup

Reputation: 610

How to copy recursive directories to a flat directory

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.

Upvotes: 3

Views: 2617

Answers (2)

myradio
myradio

Reputation: 1775

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

Upvotes: 3

choroba
choroba

Reputation: 242308

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/ \;

Upvotes: 4

Related Questions