You have a file with a funny name, probably starting with a -
. Remember that globs (like *
) are expanded by your shell, not the command being run. As an example, say you have:
$ ls -1
foo
-q
Simple enough directory, with two files in it. (The -1
option to coreutils ls
makes its output single-column.)
When you run du -sh *
, the shell notices that the second argument contains a special character (*
) and isn't quoted, so it does glob expansion. It expands it to everything that matches, in this case foo
and -q
. The effect is exactly as if you'd run:
$ du -sh foo -q
du: invalid option -- 'q'
Try 'du --help' for more information.
The error above is clear: GNU utilities allow options mixed with file names for convenience; du
is taking the file name -q
as an option. And there isn't a -q
option. (This is actually the best you can expect; worse would be if there were a -q
option, and it did something unwanted.)
Stépahane's suggestion is to change your glob to ./*
, which would result in du -sh ./foo ./-q
—which of course is taken as a file name, because it no longer begins with -
. The other option he suggests is to use --
, which tells GNU utilities that there are no more options—only file/directory names.
Really you should always use either … ./*
or … -- *
instead of *
, but we're all lazy…. Just be careful, especially if you don't trust all the file names.
du -sh ./*
ordu -sh -- *
– Stéphane Chazelas Apr 07 '15 at 20:07