How to find largest file in directory on Linux system

If you run out of disk space and would like to know which files took the most of it, us following command.

In terminal "cd" into any folder (or your home folder) and type:
du -sm *|sort -nr|less

du -sm *|sort -nr|head

"du -sm *" returns how many megabytes file takes - for all files and directories within current directory.
"sort -nr" sorts list according to the value of the first column (which is size in megabytes), and puts largest files first.
"less" is used to scroll output using cursor keys.
"head" is used if you want to print only first largest files.

No comments:

Post a Comment