Results 1 to 2 of 2
I've been searching the net for the last couple hours for the best way to consolidate my backed up pictures, music, and video into single directories. Right now they're scattered ...
- 07-27-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 1
Find directories containing a certain file type
I've been searching the net for the last couple hours for the best way to consolidate my backed up pictures, music, and video into single directories. Right now they're scattered across my backup drive in a bunch of different folders. I was able to move all my .avi files into a single directory with this command:
This works fine for movies because there aren't a ton of them and they aren't really related to any other files, but if I do that for my .jpg's or .mp3's they won't be organized by date or by album anymore.Code:find . -iname "*.avi" -exec mv '{}' /media/Backup/Movies/ \;
I know I can just find directories by using find and specifying -type d, but I don't know how to tell it to:
1. find directories containing files that end in a certain file type, and
2. Move all those directories to a new location.
Thanks for taking a look at this, any light you can shed on this is much appreciated.
- 07-29-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
It's not particularly elegant, but you could try something along these lines:
find -name "*.avi" -printf "%h\n" | sort -u | while read file; do mv $file destination_directory; done


Reply With Quote