Find and display the top 20 largest files under the current directory in descending order of disk usage.

PHOTO EMBED

Fri Sep 15 2023 10:47:38 GMT+0000 (Coordinated Universal Time)

Saved by @hardikraja #commandline

find . -type f -exec du -h {} + | sort -rh | head -n 20
content_copyCOPY

Let's break down the modifications: find /dir/ -type f -exec du -h {} +: This part of the command uses the find command to search for files (-type f) under the /dir/ directory. It then executes the du -h command on each file found. The -h flag in du makes the file sizes human-readable (e.g., in MB or GB). | sort -rh: This part sorts the human-readable disk usage in reverse order (-r) and numerically (-h). | head -n 20: Finally, the head command displays the top 20 lines (files) with the largest disk usage.