For every Linux system admin, storage is a big issue. It’s especially true when you’re running a server machine where storage can become a big factor. It’s necessary to manage the directories so that enough storage space is available whenever needed. Everyday users can also easily manage their directory for ensuring the best performance and available disk space. Let’s take a look how to find out the largest directories and files under Linux.

The command tool

We’ll be using 2 tools today – “du” and “find”. “du” will show you the biggest directories under your system whereas “find” will show the largest files available on the disk.

Finding the largest directory

At first, let’s start with directory. Run this command for finding out the largest directory under “/home” partition.

Let’s explain the details of the command:

  • du – Estimates the space usage of directory.
  • a – Display all the files & folders
  • sort – Sort text file lines
  • -n – Compare according to the numeric value of string
  • -r – Reverse the comparison(s) result
  • head – Output the first file part
  • -n (under “head” part) – Print N number of lines on the screen.

For searching and finding out the largest directory in the entire, run this command:

The size of the files/folders will be shown in bytes. If you want human readable form like KB, MB or GB etc. then run this command line:

Here, “-h” argument will tell to show human readable form. You can also add the argument in the previous commands.

Finding out the top file sizes

If you’re interested only the top file sizes of your system, then use this command:

If you’re in need of searching the largest files in a specific directory, then follow this structure:

Voila! The largest file(s)/directory(s) are discovered! Make changes accordingly to suit your needs. If your system is clogged with piles of images or small files, consider compressing them into a single archive.

Spread the love
  • 30
    Shares

PS. If you like this post please share it with your friends on the social networks using the buttons above.Thanks.

LEAVE A REPLY

Please enter your comment!
Please enter your name here