2

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.

2

This command will list the 15 largest in order:

du -xhS | sort -h | tail -n15

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.

2

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

This will show each folder in / including / itself.

  • -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)
2

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

ncdu : available in the repo of most Linux distributions.

Top Disk Usage (tdu) : A single static binary with no dependencies, written in Golang.

enter image description here

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.