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:
echo **/*.png(oL)
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).
a=() i=0
for x in **/*.png(OL); do
((i%50)) || a+=$x
((++i))
done
my-favorite-image-viewer $a
Without zsh or GNU find, there's no easy way of sorting find
output by metadata (there's find -ls
or find -exec ls
or find -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.
find . -name '*.png' |
perl -e '
$, = "\n"; # separate elements by newlines in the output
print # print…
sort {-s $a <=> -s $b} # …sorted by file size…
map {chomp;$_} <> #…the input lines (with the newline bitten off)
'
And here's a way to view every 50th file (starting with the largest):
find . -name '*.png' |
perl -e '
$, = "\n";
exec "my-favorite-image-viewer",
map {$i++ % 50 ? () : $_} # every 50
sort {-s $b <=> -s $a} map {chomp;$_} <>
'
Another approach would be to create symbolic links in a single directory, with names ordered by file size. In zsh:
mkdir tmp && cd tmp
i=1000000 # the extra 1 on the left ensures alignment
for x in ../**/*(oL); do
((++i))
ln -s $x ${i#1}.png
done
With Perl:
mkdir tmp && cd tmp
find .. -name '*.png' |
perl -e '
$, = "\n";
for $x (sort {-s $a <=> -s $b} map {chomp;$_} <>) {
symlink $x, sprintf("%06d", ++$i);
}
'
A range is simply an upper bound AND a lower bound. From the find
spec:
expression [-a] expression
Conjunction of primaries; the AND operator is implied by the juxtaposition of two primaries or made explicit by the optional -a operator. The second expression shall not be evaluated if the first expression is false.
So all you need to do is specify both size bounds before the -delete
action.
Best Answer
The 'current directory' option for
find
is-maxdepth 1
. The whole commandline for your needs is:or