[NTLUG:Discuss] Re: Is there a command line utility which will report directory statistics?
Leroy Tennison
leroy_tennison at prodigy.net
Sun Jan 22 04:59:41 CST 2006
Stuart Johnston wrote:
> Leroy Tennison wrote:
>
>> Chris Cox wrote:
>>
>>> Leroy Tennison wrote:
>>>
>>>
>>>> Graham Wilson wrote:
>>>>
>>>>
>>>>
>>>>> On Thu, Jan 19, 2006 at 06:20:47AM -0600, Leroy Tennison wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Such things as number of files,
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> find $dir -type f | wc -l
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> number of subdirectories,
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> find $dir -type d | wc -l
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> size?
>>>>>
>>>>>
>>>>> du
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> Thank you, that's exactly what I needed and would have never found by
>>>> searching. A couple of questions:
>>>>
>>>> Where is $dir documented? I thought it was a reference to a BASH
>>>> shell
>>>> variable but couldn't find either 'dir' or 'DIR' using "set | less".
>>>> Googling and trying Yahoo proved futile because both interpret the $
>>>> somehow.
>>>>
>>>> Second, I take it that 'du' reports only in blocks rather than actual
>>>> aggregates of sizes even if the '-b' switch is used, correct? The
>>>> reason I ask is that I'm looking for an equivalent of what the Evil
>>>> Empire does when it calculates directory sizes.
>>>>
>>>> Again, thanks for the help.
>>>>
>>>
>>>
>>>
>>> $dir is a variable... replace that with the directory to
>>> recurse through.
>>>
>>> Could be the current directory (you can use . for that)...
>>>
>>> find . -type d | wc -l
>>>
>>>
>>>
>>> _______________________________________________
>>> https://ntlug.org/mailman/listinfo/discuss
>>>
>>>
>>>
>> Well, that's why I'm confused. I ran it literally just as I received
>> it (didn't replace $dir with anything, just used it as-is) and it
>> worked. That's when I went looking for either 'dir' or 'DIR' in the
>> environment and checked 'man find' to see if $dir had special meaning
>> to the program. Came up empty. Then I tried Google and Yahoo only
>> to find that they treat '$' special somehow and return way too many
>> hits where $dir isn't even in the 'hit'. At that point I turned to
>> the group, still no answer to this point. The speculation I'm toying
>> with now is whether a dynamic variable is being created for the
>> duration of 'find' and destroyed at program termination. Even if
>> this is true (maybe a big if) I don't have any idea how to confirm or
>> deny it.
>
>
> In this case, $dir is a "mental variable". You're meant to do the
> variable substitution in your head as you type.
>
> Of course, $dir is also interpreted as a shell variable so you could
> set it something like:
>
> dir=/tmp
> find $dir -type d
>
> But in your case, $dir has no value so the shell turns your command into:
>
> find -type d
>
> When you run find without a path specified, it will default to the
> current directory.
>
> Hope that clears things up.
>
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
>
Thank you, of all the possibilities I could come up with, this is one
I'd have never dreamed of. Now that I re-read the man page for 'find' I
realize it's a 'feature' in that this is the intentional behavior.
More information about the Discuss
mailing list