Re: du

[prev] [thread] [next] [lurker] [Date index for 2005/09/30]

From: A. Pagaltzis
Subject: Re: du
Date: 00:57 on 30 Sep 2005
* Earle Martin <hates-software@xxxxxxxx.xxx> [2005-09-30 01:05]:
> I'd like to see how big all the files/directories starting with
> a '.' in my home directory are, please.

`.` starts with a `.` so you get a listing for the directories in
`.`.

If you don’t want that, you need to say “all file-/dirnames
starting with . and being at least 2 chars long”, which would be
`.?*`.

But that includes `..`, so you need to be more specific still:
“all file-/dirnames starting with . followed by a character
that’s anything but a . and being at least 2 chars long”, which
is `.[^.]*`.

Except that is wrong, because a file called `..blah` (unlikely as
it is) would be excluded. So you *really* want to say “all
file-/dirnames that start with a . which have exactly one more
character that must not be a ., as well as all file-/dirnames
that start with . and are at least three characters long”, and
that comes out to `.[^.] .??*`.

----

And you seem not to know that it’s not du that does anything with
the wildcard, it’s the shell. Try this:

    echo *

Or actually, maybe this:

    perl -le'print "@ARGV"' *

and you’ll see that the program never gets to see the wildcard.
Instead it sees the list of filenames that the shell expanded the
wildcard to.

That’s why you sometimes need to quote things. If you want to
output a literal asterisk, you have to write

    echo '*'

or

    echo \*

because otherwise the shell will gobble up the asterisk and
replace it with a list of filenames.

----

I suppose it’s hateful because the shell-side glob expansion
confuses novices and it’s also hateful because the dotfile
conventions make matching dotfiles properly a lot of work.

But the alternatives are even more hateful, so it’s the (far)
lesser of two evils.

Regards,
-- 
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;

Generated at 16:00 on 04 Oct 2005 by mariachi 0.52