Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output)

find / -maxdepth 1 -mindepth 1 -type d \! -empty \! -exec mountpoint -q {} \; -exec du -xsh {} + | sort -h
Excludes other mountpoints with acavagni's "mountpoint" idea, but with -exec instead of piping to an xargs subshell. Then, calling "du" only once with -exec's "+" option. The first "\! -exec" acts as a test so only those who match are passed to the second "-exec" for du.
Sample Output
4.0K    /lib64
8.0K    /media
8.0K    /srv
32K     /tmp
92K     /boot
5.8M    /sbin
7.9M    /bin
18M     /etc
45M     /lib
49M     /opt
908M    /root
1.7G    /usr
7.5G    /var
18G     /home

2019-03-06 22:17:05

2 Alternatives + Submit Alt

What Others Think

This is a brilliant and really clever improvement of my modest solution! Thank you so much also for shout me out. :) I've learned some very cool tricks from your example such as the "-empty" test and the fact that multiple "-exec" actions can be chained together and used as additional filters (didn't know that!). The only thing I feel I would change for my personal use is the -k (kilobytes) for the "du" command and the -n switch for the "sort" command (instead of -h) mainly due to compatibility reasons with older linux version (like RHEL5 etc..), in other words my ideal final version would be: find / -maxdepth 1 -mindepth 1 -type d \! -empty \! -exec mountpoint -q {} \; -exec du -xsk {} + | sort -n Cheers!
acavagni · 109 weeks and 2 days ago
Thanks for sharing information about the teacher’s attack for us. Very interesting information. Please continue to uphold.
waylanmarx · 11 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: