Results 1 to 6 of 6
Hi im trying to clean up my hard disk a little, basically i have tons of music on my hard drive and i want to try to move it all ...
- 11-24-2009 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 6
Finding all my music on hard drive and moving it to a directory for music
Hi im trying to clean up my hard disk a little, basically i have tons of music on my hard drive and i want to try to move it all in to a single directory called music. All the music is spread out in the my document directory and its sub directories below is the code i have so far but its not working any ideas? thanks in advance
#!/bin/bash
for file in /my-documents/*; do
if echo "$file" | grep -q '.mp3$'; then
mv "$file" ~/my-documents/music
echo "mp3 files moved to music folder"
else echo "No MP3 files to move"
fi
Done
- 11-24-2009 #2Linux Newbie
- Join Date
- Nov 2007
- Location
- Planet Earth
- Posts
- 152
I didn't test, but that's the ideaCode:find . -type f -name *.mp3 | while read $file do ( # maybe, you want to validate before move mv $file /path/to/music/ ) done
EOF
- 11-24-2009 #3Just Joined!
- Join Date
- Nov 2009
- Posts
- 6
Ok so i gave that a try but its saying i need to add a file operand after destination, im not rele sure what this means below is my code can u spot the problem?
thanks
#! /bin/bash
find ~/my-documents/* -type f -name "*.mp3" | while read $file
do
(
mv $file ~/my-documents/catalogs/mp3/
)
done
- 11-25-2009 #4Just Joined!
- Join Date
- Aug 2005
- Posts
- 65
does teh above solve it ?Code:#! /bin/bash find ~/my-documents/* -type f -name "*.mp3" | while read file do ( mv $file ~/my-documents/catalogs/mp3/ ) done
u can also try this
Code:find ~/my-documents/* -type f -name "*.mp3" -exec mv {} /path/to/mp3 \;
- 12-07-2009 #5Just Joined!
- Join Date
- Nov 2009
- Posts
- 6
Great Success !
Hey sorry for getting back to this so late .... yes ur first suggestion worked thanks very much. So ive set that up now im thinking i might set it up for a few other file types and give my hard drive a proper clean out, any ideas how i could have this same code running a loop so that it first searches for mp3s then moves if there is some then goes to search for jpegs and if there is any moves to jpeg dir and so on ? would i need a simple for loop or is there a better way?
- 12-08-2009 #6Just Joined!
- Join Date
- Aug 2005
- Posts
- 65
Code:for i in mp3 txt avi do find ~/my-documents/* -type f -name "*.$i" -exec mv {} /path/to/$i \; done


Reply With Quote