A counterpoint to Find is a beautiful tool, “find sucks, but is inarguably useful”.
It’s an old plan9 mailing list post, in which someone deconstructs find, and rebuilds it into something more modular, flexible, and powerful, and still compact enough to include the c and shell source code.
lr is a easy to use alternative with an expression language.
It needs to be a full blown Awk-like language, with
-v name=valuefor passing parameters. I don’t think there’s any other way to subsume all of its functionality with command line flags. It’s already a huge abuse of the command line syntax. Both operators like-aand actions like-printflook the same, and neither of them are what flags usually mean (options passed to a program). This is confusing.It already it as a pattern/action or predicate/action language, just with a bad syntax.
As I mentioned here:
https://lobste.rs/s/jfarwh/find_is_beautiful_tool#c_rkmlpz
In fact it would be pretty easy to add this to an existing Awk codebase. You just add a simple tree walk function that exposes file system metadata to the boolean evaluator and action executor. If anyone wants to work on this in Oil [1] let me know :)
[1] http://www.oilshell.org/
See also the followup email about usage, including examples.
The suggestion later in the thread to use
duinstead seems odd to me. That’s some Plan 9 shenanigans there.I love
findbut it definitely is a pain to work with.walklooks a lot nicer, although with Subversion I definitely need a prune ability that is better than grepping out the results post-facto.find’s prune is insane though.The pure plan9 version of that by Nemo is further down the thread: http://marc.info/?l=9fans&m=111558860717279&w=2
I’m not too familiar with
rc, but it looks like the script executes the given command once for each input line. I couldn’t get the script to run here. Therefore I use an equivalent script inshinstead to perform some quick tests on a Subversion checkout of the FreeBSD ports tree. The times given below are the ones towards which the commands converged after numerous runs.First only
findis used to find all the regular files inside the ports tree.It does all the work with a single process and performs the fastest.
The second command is the
shversion of thercscript. I would guess thercversion would perform similarly, since it’s doing the same thing.It’s about 100 times slower than the
findequivalent.Not “the fastest thing in the world” is quite an understatement. Spawning a new process for every input line is probably not very efficient. We can test this hypothesis by forcing
findto do the same.And indeed the performance is not too different from the previous command. So the excellent composability of the
sh(and presumablyrc) variant comes at a hefty price.And last there’s stest, which comes with dmenu.
It’s basically as fast as the regular
findversion and demonstrates that it’s possible to move the application of the predicates to the filenames into a separate command in the pipeline while maintaining good performance. It nicely avoids naively spawning a new process for every input line.