I've got a deep directory tree containing .PNG files. I'd like to find all the .PNG files in the directory, sort them in order of size from smallest to largest, and then display every 50th image.
(I'm analyzing data and trying to find the best size cutoff between "potentially useful" and "random noise" so I want an easy way to skim through these thousands of images….)
Any scripting help is appreciated. I know how to use 'find' to search by size, but not how to sort the results or run a display program to display every 50th without having it pause the process waiting.
I am using MacOS Snow Leopard, btw.
Thanks!
Best Answer
Is that size as in file size, or size as in image dimensions?
In zsh, to see all
.png
files in the current directory and its subdirectories, sorted by increasing file size:There's no convenient glob qualifier for grabbing every N files. Here's a loop that sets the array
$a
to contain every 50th file (starting with the largest).Without zsh or GNU find, there's no easy way of sorting
find
output by metadata (there'sfind -ls
orfind -exec ls
orfind -exec stat
, but they might not work with files containing non-printable characters, so I don't like to recommend them). Here's a way to do it in Perl.And here's a way to view every 50th file (starting with the largest):
Another approach would be to create symbolic links in a single directory, with names ordered by file size. In zsh:
With Perl: