Living on Linux

Sorting your movie directory


Image by iconixar - Flaticon

So say you have this directory filled with directories containing movies you legally ripped from your own collection of DVDs and BluRays. Each directory has a movie in it, but maybe also some other stuff you accidentally added to it, stuff you don't need. This will not do. Let's clean up this mess.

Make a new directory (outside of the directory containing the mess) to store the stuff to keep in.

mkdir ~/Movies

Go to the directory holding the mess.

cd <directory>

Run the following command that will go through all the directories in the current directory and it'll move all the files ending with .mkv, .mp4 and .avi to the newly made Movies directory.

find . -type f -regex '.*\.\(mkv\|mp4\|avi\)' -exec mv {} ~/Movies \;

At this point I'd remove all stuff that tends to show up in these kinds of directories and remove them.

find . -type f -iregex '.*\.\(jpg\|png\|nfo\|sub\|srt\|idx\|exe\|txt\|rar\|smi\)' -exec rm {} \;

Next I'd check to see if anything got left behind by deleting all empty directories.

find . -empty -type d -delete

And finally I'd manually go through the leftover directories (if any) and see if there's something that needs to be saved that the commands above did not find.