Results 1 to 10 of 10
Ok so I have a directory that I want to copy all the changed mp3 files from to another. I want it to retain folders and traverse as far down ...
- 01-02-2008 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 14
Get all mp3 files within a directory tree
Ok so I have a directory that I want to copy all the changed mp3 files from to another. I want it to retain folders and traverse as far down as it needs to go. Right now it only stays in the root directory. Here is my code
It only copied a single mp3 which happened to be in the Music/ directory, and didn't traverse into any sub folders. This is probably an easy answer for the pros, so thanks for your responses in advance.Code:#!/bin/bash -vx /bin/cp -u -v -p -R /media/Music/*.mp3 ~/Music/ >> ~/Scripts/music_backup.log 2>&1
- 01-02-2008 #2
2>&1
what is this for?
I'm not a shell expert, but it seems unnecessary
- 01-02-2008 #3
How about using the find command along with the exec option?
I've not tested the commands above, but hopefully you'll get an idea about how to solve your problem.Code:find /media/Music -name "*.mp3" -exec cp -uvpR '{}' \;
- 01-03-2008 #4Just Joined!
- Join Date
- Dec 2007
- Posts
- 6
Would it not be better to use something like rsync to do this task? I am new to all this so can't help you a great deal, but I think rsync is designed for this sort of task more than running scripts.
Marc
- 01-03-2008 #5Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
Don't forget the destination for cp!
That's if you want to copy into one directory. If you want to mirror the structure use rsyncCode:find /media/Music -iname *.mp3 -exec cp '{}' ./ \;Assuming you have a directory called Music in the current directory.Code:rsync -uav /media/Music ./Music
This redirects all standard errors and standard outputs so there is no output to the terminal. It's probably not that useful in this case for debugging.
- 01-03-2008 #6
Quoth coopstah13:
Quoth bigtomrodney:2>&1
what is this for?
Not quite. It redirects all standard error to standard output. So far in this thread standard output and standard error are sent to the screen (I would have said "sent to the teletype" in the old days), so it has no discernable effect.This redirects all standard errors and standard outputs so there is no output to the terminal.--
Bill
Old age and treachery will overcome youth and skill.
- 01-03-2008 #7Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
- 01-03-2008 #8Just Joined!
- Join Date
- Nov 2007
- Posts
- 14
where in this code does it specify *.mp3 only?Code:rsync -uav /media/Music ./Music
- 01-03-2008 #9Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
Where is my head today. Can you tell I'm in work

So this should exclude anything that is not an mp3 or a directory containing an mp3.Code:rsync -uav --include='*/*.mp3' --exclude='*' /media/Music ./Music
- 01-03-2008 #10


Reply With Quote
