Excluding Folders When Doing Du

Excluding Folders When Doing Du

I am trying to use du to get a list of the files/sizes on the filesystem (doing this as sudo):

cd /
du --exclude-from="/home"

and I am getting an error message, telling me that /home is a folder.

I do not want /home to be included. Looking through the du manual, it does not look like this is possible. What's the alternative to du to accomplish what I want?

1 Answer

Two things are wrong with your command:-

  • You cannot combine cd with another command, unless you add ; between them, eg cd /; du ..., though it would be better simply to specify / as a positional parameter to du, as in du ... /.
  • The --exclude-from specifies a file containing a list of search patterns: what you need is --exclude to specify the pattern in-line.

So the command you need is:

du --exclude=/home /

This will exclude /home and all its subdirectories. Note that du --exclude="/home/* / will exclude all files and subdirectories, but include the size of the /home directory itself.

5

Your Answer

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

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.