Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

After downloading tv shows and movies I would like them to be automatically moved to two separate folders (named "tv shows" and "Movies"). I know there are a lot of programs that you can do this with on windows / osx but I am not sure about ubuntu. If there are not any for ubuntu would it be possible to make some sort of script myself?

The simplest criteria that I thought of would be to sort video files over 1 hour in length to the movies folder that way it would be fully automatic. I could always make a comment on the torrent such as "movie" and then read that with a script maybe?

Any tips would be really appreciated, thanks!

share|improve this question
I can imagine how to do this with inotify or a cronjob. –  Lekensteyn Feb 28 '12 at 11:03

1 Answer 1

This script should give you something to start off with. It does a decent job in moving videos (.mp4 and .mkv, but you can add more) longer than 1 hr to ~/Downloads/Movies and others to ~/Downloads/Shows.

files=$(find -type f -name "*.mp4" -o -name "*.mkv") #include anyother formats you want
while read -r line
    time="$(ffmpeg -hide_banner -i "$line" 2>&1 | grep -Po '(?<=Duration: ).*(?=, start)'| cut -d : -f1)"
    if [[ $time -ge "1" ]] ; then
        if [ -d ~/Downloads/Movies ] ; then
            mv "$line" ~/Downloads/Movies
            mkdir -p ~/Downloads/Movies
            mv "$line" ~/Downloads/Movies
    elif [[ $time == "00" ]] ; then
        if [ -d ~/Downloads/Shows ] ; then
            mv "$line" ~/Downloads/Shows
            mkdir -p ~/Downloads/Shows
            mv "$line" ~/Downloads/Shows
done <<< "$files"

Additionally, if you are using torrent managers such as Deluge or Transmission or others that supports running scripts on completion of torrents, you can provide this as the script to run. You may have to tweak it a bit, if needed.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.