Find the Largest Files and Directories in Linux / Uncategorized / Find the Largest Files and Directories in Linux

There are several tools you can use to quickly find out which files and directories are taking up the most space on your Linux machine. In this post, I will show the methods I use most to find out what takes up free space in Linux.

Ncdu is the most popular tool to get file and directory sizes in Linux. It is not installed by default but is available in all of the default repositories of the most popular Linux distros.

To install ncdu on Ubuntu or Debian, run the command:

$ sudo apt install ncdu

On Orace/Rocky Linux/CentOS/RHEL:

# yum install ncdu.

To find out the size of all objects in a specified directory, you can run the following command:

$ sudo ncdu /var

You will see a list of files, directories, and their sizes. The ncdu tool allows you to navigate through the list of objects (using the up and down arrow keys). To expand a particular directory, press Enter. To delete a file or directory, press the d key.

ncdu - check disk space usage in linux

If you have the MC (Midnight Commander) file manager installed on your host, you can display the directory size by pressing Ctrl + Space.

Show folder size on Midnight Commander panel

If your Midnight Commander is taking a very long time to start up, you can try the following to fix the problem.

If there are no other tools available on the server, you can use the built-in du command to find out the size of the files and folders on the hard drive.

For example, the following command lists the 10 largest files or folders in the current folder:

$ sudo du -ahx . | sort -rh | head -10

The first column shows the size of the file system object, the second column shows the name.

du - find out top directoriy and file sizes in Linux

Options used:

  • . – scan the current directory
  • a – consider both the size of files and directories
  • h – convert the size to a human-readable format
  • x – skip directories on different file systems
  • sort -rh – sort results
  • head -10 – show only the first 10 entries

Get the size of objects in a specified directory:

$ du -ahx /var | sort -rh | head -10

If you only want to scan objects with a nesting level of 1::

$ du /var/* --max-depth=1 -ahx |sort -hr
The ncdu is much faster than du. Therefore, scanning the size of directories with du can take a long time on servers with a large number of objects.
One thought on “Find the Largest Files and Directories in Linux”
  1. Top 20 biggest dirs:
    # du -hcx –max-depth=6 / 2>/dev/null | sort -rh | head -n 20
    Top 20 biggest files:
    # find / -mount -ignore_readdir_race -type f -exec du -h “{}” + 2>&1 \
    Top 20 oldest files:
    # find / -mount -ignore_readdir_race -type f -mtime +30 -exec du -h “{}” + 2>&1 \

Leave a Reply

Your email address will not be published. Required fields are marked *