Using the ‘du’ and ‘sort’ commands, we can get a listing of the largest directories in a given directory. For instance, in my home directory:

jason@mintSandbox ~ $ du -h --max-depth 1 | sort -hr
7.3G	.
4.7G	./data
1.4G	./mount0
391M	./.cache
389M	./bash
258M	./tmp
104M	./texts
35M	./python
28M	./.mozilla
12M	./.adobe
11M	./.config
8.8M	./bin
8.3M	./Downloads
3.7M	./.thumbnails
1.8M	./presentations
1.3M	./.macromedia
884K	./.gstreamer-0.10
524K	./.gimp-2.8
508K	./misc
388K	./.purple
164K	./.local
152K	./.java
144K	./.netExtenderCerts
140K	./.kde
72K	./scripts
64K	./.gconf
36K	./.pki
36K	./.gftp
32K	./.gnome2
28K	./.ssh
16K	./.linuxmint
12K	./.dbus
4.0K	./mount2
4.0K	./mount1
4.0K	./.gnome2_private
4.0K	./Desktop

Here, the ‘du’ command (standing for ‘disk usage’) estimates disk space taken by directories. The ‘-h’ option tells ‘du’ to make the output human readable. The ‘–max-depth 1′ option tells ‘du’ not to dig down within folders. (Try issuing the command without this option and see what happens.) The ‘sort’ command then takes the output of ‘du’ and sorts it by human readable numbers (again, the ‘-h’ option). The extra ‘-r’ option simply tells sort to reverse the sort, so the largest folders come first. We could pipe this to ‘head’ to reduce the number of rows returned to, say, 5 rows:

jason@mintSandbox ~ $ du -h --max-depth 1 | sort -hr | head -n 5
7.3G	.
4.7G	./data
1.4G	./mount0
391M	./.cache
389M	./bash
Posted in Linux
Share this post, let the world know

Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">