[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua OS
- From: Coda Highland <chighland@...>
- Date: Mon, 23 Apr 2012 20:46:20 -0500
>> proc{'find', "/usr", "-name", pattern, "-print0"}.pipe{'xargs', '-0', 'du'}()
>>
>> find /usr -name "$pattern" -print0 | xargs -0 du
>>
>> find /usr -name $pattern -print0 | xargs -0 du
>
> My thought would be something a little more verbose, like:
> proc1 = create_process('find', {path='/usr', name=pattern, print0=true})
> proc2 = create_process('xargs', {nullsep=true, delim='u'})
> proc1.stdin = proc2.stdout
> proc2:start(); proc1:start()
du is the command xargs is invoking; it's "disk usage", not a
delimiter command to xargs. >.>
That said. None of those are appropriate!
Try this:
for file in path.find{basedir="/usr", name=pattern} do
print file, fs.stat(file).size
end
If you're thinking about it using your bash/POSIX idioms you're not
taking advantage of the fact that you have a scripting language! Not
to mention this runs faster and with less memory because you're not
constructing a list of files and then passing them to a second
process; path.find can return an iterable that sifts through the
filesystem incrementally -- and the stat cache can be shared between
the find process and the size lookups.
And this avoids the obvious question of "what does this snippet do?"
because the code is more self-documenting in the process!
/s/ Adam