I am impressed by the sheer amount of functionality offered by the
Unix find
command, but remain unable to remember how to use it
for anything other than the basics; otherwise I hit Google.
Obviously I don't have a very good memory for flags, but I do remember
expressions. findr
is given exactly two arguments; the base directory
and a filter expression:
$ findr . 'path.ext=="rs" && path.size > 1kb'
$ findr . 'path.is_file && date.before("1 jan")'
$ findr . 'path.ext=="md" and date.after("last tuesday")'
The filter expression is passed path
and date
and fairly arbitrary
expressions are supported, thanks to the very capable little embedded
language rhai. As a little
convenience, "and", "or" and "not" are understood, since these are
easier to type in a hurry.
path
has the following fields:
is_file
is this path a file?is_dir
is this path a directory?size
size of file entry in bytesext
extension of file pathfile_name
file name part of pathdate
has the following methods:
before(datestr)
all files modified before this dateafter(datestr)
all files modified after this datebetween(datestr,datestr)
all files modified between these datesNumbers may have a size prefix (kb,mb,gb - not case-sensitive) and date strings are interpreted by chrono-english.
No Flags Mini-philosophy:
Currently, findr
ignores hidden directories, and speaks British English (i.e. not "9/11").
The idea is that such options will be passed as environment variables such as FINDR_US
.
To illustrate my point about flags, the equivalent of findr . 'path.ext="rs"'
is:
find . -type d -path '*/\.*' -prune -o -not -name '.*' -type f -name '*.rs' -print
(I had to look that one up)