Re: [dev] alternatives to find for querying the filesystem
On Thu, Dec 12, 2013 at 02:32:03PM -0500, Andrew Gwozdziewycz wrote:
> find(1) seems very un-unixy, but it's very powerful.
It's not, though, because ultimately it's just a file system walk with a
system for querying stat(2). No, the problem I have with find is that
its output is not necessarily safe for easy usage in common shell
situations. That's what I have zsh's globbing for. (Seriously, recursive
globbing is the only reason I don't use mksh yet)
> Let's assume for
> a minute that find didn't exist. How would you do the following:
>
> 1. execute a command for each file (find . -exec whatever {} \;)
whatever **/*
> 2. find files that are > 8M
print -l **/*(LM+8)
> 3. find files that are older than 20 days
print -l **/*(m+20)
> 4. find all files that are owned by 'joe' that also have execute
> permissions for world
>
print -l **/*(u.joe.X)
[...]
> Thoughts? Pointers to tools that already do this?
>
All of the above have the same problem: If I do
for i in $(find . -foo); do
...
done
then this will fail if any file contains something in IFS. If I do
find . -foo | while read line; do
...
done
then this will fail for files with a newline in the name. Granted, that
doesn't happen often, but I don't want to think about such trivialities
in shell scripts that might work with untrusted data. If I do
for i in **/*(flags); do
...
done
then zsh will expand the glob correctly, no matter what those file names
contain. And in none of the above is the situation improved by replacing
find by another, more limited tool, because the problem is the interface
between tools and the shell.
> Cheers,
>
> Andrew
> --
I think that should be dash-dash-space.
Ciao,
Markus
Received on Fri Dec 13 2013 - 00:08:51 CET
This archive was generated by hypermail 2.3.0
: Fri Dec 13 2013 - 00:12:27 CET