Filter ls output based on file size
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Filter Ls Output Based On File Size
00:30 Answer 1 Score 13
00:56 Answer 2 Score 4
01:05 Accepted Answer Score 6
01:38 Answer 4 Score 0
01:45 Thank you
--
Full question
https://superuser.com/questions/284349/f...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#commandline #bash #ls
#avk47
ANSWER 1
Score 13
You can do that using find
:
find . -type f -size +100k | grep '.png\|.jpg'
Where +100k
specifies the size in KB, meaning that only files larger than this should be output. find
also has some other nice options, for example to only list files that were created a certain amount of time ago. See man find
for more details.
The above could also be rewritten as
find . -type f -size +100k -name "*.png" -o -name "*.jpg"
ACCEPTED ANSWER
Score 6
As others have suggested, find
will allow you to find files in specified size ranges. Find
outputs just the path to each file, though. Also, without further qualification, find
will find all the files in the current directory and in every directory below the current directory. The following searches only the current directory and uses ls
to dispaly the results.
find . -maxdepth 1 -size +200 \( -name \*.png -o -name \*.jpg \) -print | xargs ls -ldh
Note that the size is in blocks, where a block is often if not always 512 bytes.
ANSWER 3
Score 4
Use find
instead of ls
:
find . -type f -size +100k \( -name \*.png -or -name \*.jpg \)
ANSWER 4
Score 0
Using du
du -a --apparent-size -t +100k | grep '.png\|.jpg'