How to Find Out Top Directories and Files (Disk Space) in Linux

As a Linux administrator, you must check time to time which files and folders are eating more disk space. It is very necessary to find the unnecessary junks and free up them from your hard disk to avoid overrunning the disk usage.

This tutorial describes how to find the largest files and folders in the Linux file system using du and find command. If you want to learn more about these two commands in

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

The command above shows top 5 directories taking up the most of space.

Let us break down the command and see what each parameter has.

  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).

The following command will list direct sub directories in current directory eating up more space in your machine. To view full path to largest directories see the next command.

The following will show the full path to most spacing taking directories within your current working directory.

The command above is very useful to find the actual location of the directory eating up most of the space in your machine. You can simply go and explore the listed directories and delete them if they are not required.

Find out the meaning of each options using in above command:

  1. du command: Estimate file space usage.
  2. -h : Print sizes in human readable format (e.g., 10MB).
  3. -S : Do not include size of subdirectories.
  4. -s : Display only a total for each argument.
  5. sort command : sort lines of text files.
  6. -r : Reverse the result of comparisons.
  7. -h : Compare human readable numbers (e.g., 2K, 1G).
  8. head : Output the first part of files.

Find Out Top File Sizes Only

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

To find the largest files in a particular location, just include the path besides the find command:

OR

Filter files by File name

The following command will provide files under home directory which end with “log” tail. For example yoursite.php.error.log

Find files greater than [ > size]

The following command will list all the files which are greater than 5MB and ends with “log” in its name

Also read:

One thought on “How to Find Out Top Directories and Files (Disk Space) in Linux

Leave a Reply

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