Organize a TV-Series season

season=1; for file in $(ls) ; do dir=$(echo $file | sed 's/.*S0$season\(E[0-9]\{2\}\).*/\1/'); mkdir $dir ; mv $file $dir; done
It happened to me that I got a season of a tv-show which had all files under the same folder like /home/blah/tv_show/season1/file{1,2,3,4,5,...}.avi But I like to have them like this: /home/blah/tv_show/season1/e{1,2,3,4,5,...}/file{1,2,3,4,5,...}.avi So I can have both the srt and the avi on one folder without cluttering much. This command organizes everything assuming that the filename contains Exx where xx is the number of the episode. You may need to set: IFS=$'\n' if your filenames have spaces.

-1
By: lonecat
2009-05-27 03:30:58

These Might Interest You

  • Identify Movies but NOT TV Series using find and regex While it's easy to find video files, it's not easy to check wheter they are Movies or part of TV Series; this could be important if you need to move files before cataloguing them. Using Regex this could become possibile. Normally TV Series are names with Season and Episode numbers in the file name, this way: "X-Files S01E12 - Gna gna gna.avi" or "3x04.Falling.Skies.-.The.Revenge.mkv" and so on. This RegEx will find correct Episodes if they have the structure "S00E00" or "0E00" or "S00x00" or "0x00". Inversing RegEx makes the trick to find out Movies.


    0
    find . -type f -regextype posix-extended ! -regex '^.*[S|s|\.| ]{0,1}[0-9]{1,2}[e|x][0-9][0-9].*\.(avi|mkv|srt)$' \( -iname "*.mkv" -or -iname "*.avi"-or -iname "*.srt" \)
    marcolino · 2017-05-08 10:56:21 0
  • While it's easy to find video files, it's not easy to check wheter they are Movies or part of TV Series; this could be important if you need to move files before cataloguing them. Using Regex this could become possibile. Normally TV Series are names with Season and Episode numbers in the file name, this way: "X-Files S01E12 - Gna gna gna.avi" or "3x04.Falling.Skies.-.The.Revenge.mkv" and so on. This RegEx will find correct Episodes if they have the structure "S00E00" or "0E00" or "S00x00" or "0x00". In case you should need to find Movies but NOT TV Series, you have to inverse the RegEx when finding video files: find . -type f -regextype posix-extended ! -regex '^.*[S|s|\.| ]{0,1}[0-9]{1,2}[e|x][0-9][0-9].*\.(avi|mkv|srt)$' \( -iname "*.mkv" -or -iname "*.avi"-or -iname "*.srt" \)


    0
    find . -type f -regextype posix-extended -regex '^.*[S|s|\.| ]{0,1}[0-9]{1,2}[e|x][0-9][0-9].*\.(avi|mkv|srt)$'
    marcolino · 2017-05-08 10:16:07 0
  • { ... } vs ( ... ) reduces the process count, I believe. Typically, I use this logic to redirect a series of commands to a pipe -- { command1 args1 ; command2 args2}|less -- or file -- { command1 args1 ; command2 args2}>foo -- or to spawn the series as a background process -- { ... } & .


    0
    { command1 args1 ; command2 args2 ; ... }
    IF_Rock · 2011-04-12 20:01:51 0

  • 2
    seq 1000 | paste -sd+- | bc
    rubenmoran · 2011-02-09 20:03:49 1

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: