19

I face disk space full issue in Linux. When checked with df command I found the '/' directory is occupying 100%. So to check which folders consume much space I ran cd / and du -sh. But it takes forever to run the command. But ultimately I want to get the details on which top immediate sub folders of '/' folder are consuming huge disk space. So can any one tell the command for the same.

6 Answers 6

25
du -h --max-depth=1 / | sort -h -r

This will show each folder in / including / itself.

Mind that this could take a long time to scan through all the files. If you require any specific sizes of the subfolders in a folder, specify the exact path of the folder instead of / or just skip / if you're already in that folder.

  • -h options shows sizes in human friendly format
  • --max-depth=1 instructs command to go only 1 directory deep inside /
  • sort -h -r sorts results using human friendly sizes and -r instructs command to show results in reverse order (from largest to smallest directories)
1
  • 1
    Here is osx version: du -h -d 1 / | sort -h -r Commented Mar 23, 2022 at 15:37
14

This command will list the 15 largest in order:

du -xhS | sort -h | tail -n 15

We use the -x flag to skip directories on separate file systems.

The -h on the du gives the output in human-readable format, sort -h can then arrange this in order.

The -S on the du command means the size of subdirectories is excluded.

You can change the number of the tail to see less or more. Super handy command.

0
10

Two other open source command line tools, that display top disk space used, are:

ncdu

Available in the repo of most Linux distributions.

screenshot

Top Disk Usage (tdu)

A single static binary with no dependencies, written in Golang.

You want to know what is using all your disk space ? This command-line tool estimates the disk space occupied by all files in a given path. It displays a sorted list of the biggest items. The estimation method is similar to the 'du -skx' command from GNU Coreutils package.

screenshot

1
  • Wow, this is so much easier. Thanks so much for sharing this. Commented Jun 6, 2020 at 15:57
3

I allways use

cd /
du -sch ./*

This will show you all folders from the root folder and their used disk space.

After getting the usage from all parent directories, change in the next child folder and repeat the 'du' command from above. Repeat that stepts to find your big files and folders.

You need to go from folder to folder to find out whats going on.

Edit: May be you want the "x" flag as well if you have multiple partions mounted. The 'x' will only count usage on one filesystem and exclude other mounts.

du -schx ./*
0

The command du -hs /* will list all top directories seperatly.

0

The following command worked:

du -xh -d 1 | sort -h 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.