Shell script to find largest PNG files in directory recursively
The following shell script finds the largest PNG files in a directory recursively and prints their sizes in human-readable format:
find . -iname "*.png" -type f -exec du -h {} + | sort -rh | head -n
where:
find . -iname "*.png"
searches for all PNG (case-insensitive:.png
or.PNG
etc) files in the current directory (.
) and subdirectories-type f
ensures that only files are considered (not directories)-exec du -h {} +
executes thedu
command on each found file, printing their sizes in human-readable formatsort -rh
sorts the output in reverse order by sizehead -n
limits the output to the topn
largest files
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow