Speaktech.in

Linux display the largest folders files including the sub-directories

find -type f -exec du -Sh {} + | sort -rh | head -n 5

The command parameters are.

  1. du command: Estimate file space usage.
  2. a : Displays all files and folders.
  3. sort command : Sort lines of text files.
  4. -n : Compare according to string numerical value.
  5. -r : Reverse the result of comparisons.
  6. head : Output the first part of files.
  7. -n : Print the first ā€˜n’ lines. (In our case, We displayed first 5 lines).

Run the following command to find out top biggest directories under /home partition.

# du -a /home | sort -n -r | head -n 5


To display the largest folders/files including the sub-directories, run:

du -Sh | sort -rh | head -5