This is a unique situation

I've more than 500 Movies in a partition. what I wanted to do is search movie files on the basis of Property Video Dimension, so that I could delete anything which is below 720p HD, to make space for other stuff.

Search option in nautilus can search by dates or file types but not properties. is there another application that i can use? or Command? or Nautilus-Script?

Highlighting video dimension


find . -name '*.mkv' -exec exiftool -fileName -imageSize {} \; 

This command works as expected but i want this command to do a little bit more. i don't know how ExifTool works so i can't modify it

can I add multiple file extensions in single command? most of the files are mkv but it includes mp4 flv. a single command scanning all these video extensions could save a lot of work

enter image description here

(see how many sub folders are there)

  • askubuntu.com/questions/249828/… with some combination of find and grep. – muru Apr 3 '17 at 9:14
  • @muru i read that question, my beginners ubuntu mind could grasp what it could but it's still really unclear to me, can there be a nautilus-script for this? because i don' want to use other file managers – Sumeet Deshmukh Apr 3 '17 at 9:24
  • This might lead you in the right direction unix.stackexchange.com/questions/85949/… – bart Apr 3 '17 at 9:37
  • @bart exiftool did work, but there are a few minor problems. i've updated the question accordingly, thanks for the help – Sumeet Deshmukh Apr 3 '17 at 10:55
  • As mentioned by @muru you will have to use a combination of tools and pipe the output between them, there is no easy solution as any attempt of rm on you file system can have catastrophic effect. Use "man find" to get all your files pipe that to "man exiftool" and you can drop the output to file with ">" – bart Apr 3 '17 at 11:17

Enable extended and recursive globbing:

shopt -s extglob globstar


exiftool -q -p '$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv)

** will recurse into subdirectories. The extended glob +(*.mp4|...) will match at least one of the patterns inside the ().

You can use grep to process the output and generate a list of files not 1920x1080:

exiftool -q -p '$Directory/$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv) |
  grep -v ' 1920x1080$'

Note the change here: I'm using $Directory/$FileName $Imagesize. We need the path to the file, not just the filename, so $Directory/$Filename. And Here we check if each line doesn't end with 1920x1080 ($ is the end of line, -v in grep inverts the match). Verify the output.

Now we can delete these files:

exiftool -q -p '$Directory/$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv) |
  grep -v ' 1920x1080$' | sed 's: [^ ]*$::' |
  xargs -d '\n' rm

sed 's: [^ ]*$::' removes everything from the last until the end of the line, so the AxB resolution from the output of exiftool is removed, keeping only the filename. Then xargs rm takes each line as a filename and runs rm with them as argument.

Disable the globbing options when done:

shopt -u globstar globstar

To exclude multiple resolutions, use an OR in grep:

grep -Ev ' (1920x1080|1920x820|1280x544)$'

Here is a command with all the widely used video formats

exiftool -q -p '$Directory/$FileName $ImageSize' **/+(*.mp4|*.mkv|*.flv|*.avi|*.webm|*.vob|*.mov|*.wmv|*.amv|*.m4p|*.m4v|*.mpeg|*.mpv|*.m4v|*.3gp)

Here is a command excluding (almost) all the HD Video formats

grep -Ev ' (1920x1080|1920x1040|1920x1068|1906x952|1916x808|1920x808|1920x804|1916x812|1600x864|1436x1080|1920x820|1280x544|1920x800|1920x802|1920x816|1856x1080|1920x1072|1920x1056|1280x720|1280x536|1280x560|1280x538|1280x528|1216x544|1280x534|1280x532|1281x534|1278x714|1280x718|1280x688|1278x682|1280x690|1280x694|1280x660|1282x692|1280x692|1285x696|1278x544|1280x696|1279x718|1280x546|1281x546|960x720|1324x552|1305x552|1308x552|1536x640)$'
  • Nice one, so simple :) – bart Apr 3 '17 at 11:54
  • Can we exclude multiple resolutions too? For eg 1920x816, 1920x820, 1280x544 , I'm talking about all the resolutions that can be defined as HD or above. I want to keep those (i should probably stop, I'm asking for more and more) – Sumeet Deshmukh Apr 3 '17 at 11:54
  • just tried it and it worked (couldn't try it before), "it worked" is an oversimplification, it worked like charm. if you could update the answer with code to exclude at least two resolutions i can add all the others on my own. if you can't, that's fine too, i can live with this! linux is amazing, let me upvote that answer – Sumeet Deshmukh Apr 3 '17 at 12:10
  • @SumeetDeshmukh see update. – muru Apr 3 '17 at 12:11
  • @muru thanks, again deleted 125Gb – Sumeet Deshmukh Apr 3 '17 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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