So basically, I have a folder with a bunch of subfolders all with over 100 files in them. I want to take all of the mp3 files (really generic extension since I’ll have to do this with jpg, etc.) and move them to a new folder in the original directory. So basically the file structure looks like this:
/…/dir/recup1/file1.mp3
/…/dir/recup2/file2.mp3
… etc.
and I want it to look like this:
/…/dir/music/file1.mp3
/…/dir/music/file2.mp3
… etc.
I figured I would use a bash script that looked along these lines:
#!/bin/bash
STR=`find ./ -type f -name \*.mp3`
FILES=(echo $STR | tr ".mp3 " "\n")
for x in $FILES
do
echo "> [$x]"
done
I just have it echo for now, but eventually I would want to use mv to get it to the correct folder. Obviously this doesn’t work though because tr sees each character as a delimiter, so if you guys have a better idea I’d appreciate it.
(FYI, I’m running netbook Ubuntu, so if there’s a GUI way akin to Windows’ search, I would not be against using it)
If the
musicfolder exists then the following should work –A
-exec commandmust be terminated with a;(so you usually need to type\;or';'to avoid interpretion by the shell) or a+. The difference is that with;, the command is called once per file, with+, it is called just as few times as possible (usually once, but there is a maximum length for a command line, so it might be split up) with all filenames.