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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like