Thursday, July 26, 2012

Finding/opening your smallest/largest images/files

So I have a folder of about 14K pictures and videos, and I decided to try to find the smallest images in my set (I was actually looking for the darkest ones, and it kinda worked). So I made up this command, and it works out nicely:

open $(find . | grep JPG | xargs ls -all | sed 's/  */ /g' | cut -f 5- -d' ' | sort -nr | tail -n 500 | cut -f 5 -d' ')



Logical steps:
  1. find . : Shows all files inside the current directory, and recursively inside all subdirectories.
  2. grep JPG : Remove all no-JPG files from the list (folders, system files, video files, etc).
  3. xargs ls -all : Re-list all the files, this time with all file attributes (size, permissions, etc).
  4. sed 's/ */ /g' : Replace all space sequences with a single space.
  5. cut -f 5- -d' ' : Grab only the attributes starting from the file size column (this might vary depending on your ls default attributes. Tweak the "5" to accomodate your own settings).
  6. sort -nr : Sort descendingly by file size.
  7. tail -n 500 : Grab only the 500 last files (I didn't want to open ALL of them).
  8. cut -f 5 -d' ' : Grab only the actual filename (remove all other attributes).
  9. open : Open them in Preview! (Or whatever your default image-viewing application is).
  10. View!

No comments:

Post a Comment