There are lots of fancy programs for Linux to find out where your gigabytes are sitting and filling your hard drive, the simplest of them is du (from disk usage). The trick is to use the --max-depth=1 option so that you get a view of which folder weighs how much. Try this:


peterbe@trillian:~/tmp $ du -h --max-depth=1
900K    ./Example-Receipts
4.0K    ./Foredettinghelgen
44K     ./IssueTrackerBlogInterface
1.9M    ./IssueTrackerProduct
12K     ./fried-mugshots
2.1M    ./ies4linux-2.0.5
4.8M    ./pyexcelerator
52K     ./levenstein
4.0K    ./newitpdesign
4.7M    ./photoresizing
69M     ./databases
4.5M    ./i18nextract-sa
532M    .

Pretty nifty! That way you can quickly see which folder contains the most junk so that you can free up some hard drive space.

To sort it I don't know how to reformat it into human readable values but there's the command:


peterbe@trillian:~/tmp $ du --max-depth=1 | sort -n
4       ./Foredettinghelgen
4       ./newitpdesign
12      ./fried-mugshots
44      ./IssueTrackerBlogInterface
52      ./levenstein
900     ./Example-Receipts
1856    ./IssueTrackerProduct
2140    ./ies4linux-2.0.5
4528    ./i18nextract-sa
4796    ./photoresizing
4872    ./pyexcelerator
70392   ./databases
544608  .

Comments

Post your own comment
Anonymous

You can use -h option for human readable values. (i assume the convertion of bytes to Megabytes, kilobytes etc is what you by human readable values, )
du -h --max-depth=1.

Comment for a very old post... Came across ur site while i was googling for something.

- SS

Anonymous

also sort can take -h values with:
sort -h

Anonymous

Thanks .. Very helpful Post :)

Anonymous

Workaround to sort AND have human-readable values:

du -BM --max-depth=1 | sort -n

(or to see it sorted largest first):

du -BM --max-depth=1 | sort -nr

Caveat: This displays everything in Megabytes, so the smallest unit you will see is 1M. If you need to see it in Kilobytes just change the "M" to a "K".

jhon02@msn.com

human readable just add du -hx --max-depth=1 | sort -n

Llauro

You can get that in human readable form using two commands:

To get the total amount of each subdirectory of the actual one (does not summarizes):
du -hs * | sort n

To get the total amount of the actual whole tree:
du -hs

I have been not able to summarize the whole tree showing the size of each first subdirectory. Something like 'du -hs * ..' or 'du -hs .' does not work for that.

Frédéric Esnault

To display disk usage with human readable values and sort them using the human readable value order, use this command :

du -h | sort -h

Anonymous

It still helpful in 2017! Thank you!

Anonymous

Still works great in 2017

Anonymous

*2018

Anonymous

the truth remains :) :)

Anonymous

This is it!
Thank you :)

Julez

sudo du from my home path to see who my space hogs are and measure quotas. Works well. 2018

Tommy

Nice thanks!

Anonymous

Sweet!

Anonymous

still relevent

Anonymous

you can do this to have with human readable value

du -hs --max-depth=1 | sort -hr

Erg

Still works :)

Anonymous

Awesome option

Anonymous

damn this post is older than me

Rolo

Still useful today... probably a very very useful post...

Peter Bengtsson

Probably? :)

Anonymous

2022 mate, still useful :)

Heman

January 2022 and you just saved hours of my time Peter! Looking at command help, I kept on adding the -X option before --max-depth=n and it kept failing! One minute on your article and BAM! I Have the required output on my trial folder. Now this command is running on a humongous folder in the background with the help of nohup and &! You are a true rockstar!

Anonymous

it does not work

Anonymous

2022 March.Still working.Great!!!

Anonymous

This post ages like fine wine. Just what I needed.

Anonymous

I used this page as a regular reference. No need to update.

Your email will never ever be published.

Related posts

Go to top of the page