linuxshellwarningssuppress-warningsdu

Exclude all permission denied messages from "du"


I am trying to evaluate the disk usage of a number of Unix user accounts. Simply, I am using the following command:

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

But I’ve seen many error message like below. How can I exclude all such “Permission denied” messages from display?

du: `./james/.gnome2': Permission denied

My request could be very similar to the following list, by replacing “find” to “du”.

How can I exclude all "permission denied" messages from "find"?

The following thread does not work. I guess I am using bash.

Excluding hidden files from du command output with --exclude, grep -v or sed


Solution

  • du -cBM --max-depth=1 2>/dev/null | sort -n 
    

    or better in bash (just filter out this particular error, not all like last snippet)

    du -cBM --max-depth=1 2> >(grep -v 'Permission denied') | sort -n