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?
Asked
Active
Viewed 1.5k times
8
-
You can copy everything then delete the .wav files by extension in that folder and subfolders – Parto Jun 13 '16 at 11:46
-
copy of See this solution – Ziazis Jun 13 '16 at 11:46
-
@parto the op probably wants to avoid the time delay in copying the same (maybe large) audio file 20 times when they don't need to – Azor Ahai -him- Jun 13 '16 at 17:20
2 Answers
14
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

heemayl
- 91,753
-
1Excellent!! Thank you so much for the beautiful explanation. Worked like a charm! – optimist Jun 13 '16 at 12:17
-
@optimist if the answer solved your question, please accept this answer as a valid solution by clicking the grey checkmark next to the up and down arrows. Thank you for cooperation and welcome to AskUbuntu ! – Sergiy Kolodyazhnyy Jun 13 '16 at 12:18
0
The easiest way is proably to use rsync:
rsync -avz --exclude "*.wav" SOURCE_DIR DESTINATION_DIR

Julen Larrucea
- 1,042
- 11
- 25