Post by StrakePost by sinfind: Useless, just do `du -a | grep blabla'
Yes, this is what one does on Plan 9.
Which doesn't necessarily make it right.
Post by StrakePost by sinI realize when xargs is useful, I just hate it.
Yep, the basic function is sane, but the other crap, insert mode and
quotation and such, loses.
So just don't implement the insane bits! Does anybody here use anything
but â-dâ or â-0â and/or â-Lâ?
Post by StrakePost by sinI'm not interested in disk usage, but finding files based on certain
properties, such as update time, ownership, permissions, etc.
du -a | cut -f 2
No. âdu -0 | cut -f 2-â, at least.
And what the heck? That has nothing to do with what *you* just quoted above.
We're talking about checking *update time*, *ownership*, *permissions*,
etc., not the file name. This means I have to wrap in shell, and before
I know it, my little traversal of a few million files (not kidding, real
use case, though it's noticeable for smaller numbers) takes longer, not
to mention that it's more code.
du -a \
| cut -f 2- \
| while read -rd f; do
if (($(stat --format=%a "$f") & 0111)) &&
[ $(stat --format=%u "$f") = $(id -u) ] &&
[ "$f" -nt $reference ] &&
[ -f "$f" ]; then
chmod a-x "$f"
fi
done
Still have to figure out how to make it work with âdu -a0â, without
using the following.
awk 'BEGIN { RS="\0" } { sub("^[0-9]+[[:space:]]*", "", $0); print $0 }'
I've heard that the above is non-portable due to the use of nul as the
record separator. Should we care? It neither works with nawk or Plan 9
awk.
You can cut a line or two if in the previous while loop if you make it
slightly less readable but the point still stands, whereasâŠ
find -print0 -perm /111 -uid $(id -u) -type f -cnewer $reference | xargs -0 rm
is short and sweet.
Please don't implement â-deleteâ. It's both redundant and not in POSIX.
Are there any other considerations that would make us want it?
du's output is standardized
(http://pubs.opengroup.org/onlinepubs/009604499/utilities/du.html#tag_04_40_10),
mercifully, though that doesn't mean it makes handling a few special
cases easy. Should we care about any such? The only ones that I can
think of right now are newlines in the file names, which is pretty
stupid but possible.
Using du is brittle but you can use it without fear the overwhelming
majority of the time. Still, if you advocate strong typing as a Haskell
programmer, why wouldn't you in shell (well, not shell itself) as
appropriate?
Regards,
Alex Pilon