How to copy an entire directory except one file in each sub-directory via terminal? [duplicate]
I have a folder named 'Java' which has 20 sub folders ('Day-01' to 'Day-20'). Each sub folder has one or two '.wav' files along with few other files. I want to copy the entire directory except the '.wav' files via terminal. How do I do this?
Solution 1:
The easiest way would be to use rsync
with the --exclude
option to exclude to .wav
files from copying:
rsync -av --exclude='*.wav' /path/to/Java /out/dir
Example:
/foobar/Java% tree
.
├── day-01
│ ├── 01.sh
│ ├── 01.txt
│ └── 01.wav
├── day-02
│ ├── 02.sh
│ ├── 02.txt
│ └── 02.wav
├── day-03
│ ├── 03.txt
│ └── 03.wav
├── day-04
│ └── 04.txt
└── day-05
└── 05.wav
/foobar/out% rsync -av --exclude='*.wav' ../Java .
sending incremental file list
Java/
Java/day-01/
Java/day-01/01.sh
Java/day-01/01.txt
Java/day-02/
Java/day-02/02.sh
Java/day-02/02.txt
Java/day-03/
Java/day-03/03.txt
Java/day-04/
Java/day-04/04.txt
Java/day-05/
sent 564 bytes received 158 bytes 1,444.00 bytes/sec
total size is 0 speedup is 0.00
/foobar/out% tree
.
└── Java
├── day-01
│ ├── 01.sh
│ └── 01.txt
├── day-02
│ ├── 02.sh
│ └── 02.txt
├── day-03
│ └── 03.txt
├── day-04
│ └── 04.txt
└── day-05