Subject: Re: bug#6582: minor issue with du command

From: Bob Proulx <[email-masked]>
Date: Wed, 7 Jul 2010 17:07:07 -0600

Warren L Dodge wrote:
> I did a du -s * .??* in my /tmp directory and got this
> 
> du: invalid option -- 1
> du: invalid option -- 2
> du: invalid option -- 3
> 
> It turns out I had a directory named of all things "-123"

Yes, that would do it.

> It seems like there would be a way to stop processing switches. But
> it looks like even if I put -123 as the last file of 30 others it
> still processes it as a switch.

That is a good idea!  Hmm...  What can we do about that.  After due
consideration we have added a way to stop processing arguments as
options.  Put a "--" on the command line after all of your option
arguments and before your file arguments.  Check your system as we
have already updated it. :-)

  du -s -- -123
  du -s -- * .??*

Or traditionally prefixing the filename with a "./" also avoids having
the file look like an option argument.

  du -s ./-123
  du -s ./* ./.??*

> No big deal since this doesn't happen to much (I assume).

Unix folk tend to avoid filenames that start with an option letter or
that contain spaces.  Why cause trouble?  But for robust operation you
should always use either ./ or -- to avoid a filename being parsed as
an option argument and creating a data dependent failure.

Bob