How to Find Out Disk Space and Files size in Linux

Disk-Space

  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 the files. -5 Show 5 Directory result
  7. -n: Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).

using du with human-readable sizes and a maximum depth of 1 directory level is as follows:

du -h --max-depth=1

This command will display the sizes of the directories in the current location with human-readable sizes and limit the display to a maximum depth of 1 directory level.

display the largest files in KB, MB, or GB.

du -hs * | sort -rh | head -5

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

du -Sh | sort -rh | head -5

Find Out Top File Sizes Only

If you want to display the biggest file sizes only, then run the following command

find -type f -exec du -Sh {} + | sort -rh | head -n 5
find /home/downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
Or
find /home/downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5

Related posts

Creating a Bootable Installation Media for Ubuntu OS

Secure Your Website with Let’s Encrypt and Nginx: A Step-by-Step Guide

Monitoring Calls with FreeSWITCH CLI: A Comprehensive Guide