You need to figure out what directories include .wav
files:
find . -type d \
-exec sh -c 'set -- "$1"/*.wav; [ -e "$1" ]' sh {} ';' \
-print
This goes through all directories under .
and tries the glob pattern *.wav
in all of them. If the pattern is unexpanded, then we assume that there is no .wav
file there (this will fail if there is a file with the literal name *.wav
in a directory and no other .wav
files in the same directory).
Then we may incorporate rsync
into the above command to sync these directories:
find . -type d \
-exec sh -c 'set -- "$1"/*.wav; [ -e "$1" ]' sh {} ';' \
-exec rsync -a {} /path/to/destination/ ';'
This will create a subdirectory under /path/to/destination
for each directory found to contain a .wav
file.
Testing:
$ tree Source
Source
|-- A
| |-- a.wav
| |-- hs.doc
| `-- hy.xls
|-- B
| |-- hs.doc
| `-- py.xls
`-- C
|-- CA
| |-- d.wav
| |-- h.doc
| `-- h.xls
`-- CB
|-- h.doc
`-- hd.xls
5 directories, 10 files
Running the command:
$ find Source -type d -exec sh -c 'set -- "$1"/*.wav; [ -e "$1" ]' sh {} ';' -exec rsync -a {} Dest/ ';'
Checking the result:
$ tree Dest
Dest
|-- A
| |-- a.wav
| |-- hs.doc
| `-- hy.xls
`-- CA
|-- d.wav
|-- h.doc
`-- h.xls
2 directories, 6 files
The Dest
directory was already existing, but empty.
rsync
is doing nothing with the list of files generated byfind
. What do you actually want to achieve (preferably with examples)?