forkmeGo home

efind

Introduction

efind (extendable find) searches for files in a directory hierarchy.

Basically it's a wrapper for GNU find providing an easier and more intuitive expression syntax. It can be extended by custom functions to filter search results.

A quick example

Let's assume you want to find all MP3 (*.mp3) and Ogg Vorbis (*.ogg) files that were modified less than two days ago in your music folder. That's no problem with efind's self-explanatory expression syntax:

$ efind ~/music '(name="*.mp3" or name="*.ogg") and mtime<2 days'

Additionally you can filter the search result by audio tags and properties with the taglib extension:

$ efind ~/music '(name="*.mp3" or name="*.ogg") and mtime<2 days \
  and artist_matches("Welle: Erdball") and audio_length()>200'

Usage

Running efind without any argument the search expression is read from standard input (stdin) and files are searched in the user's home directory. A different directory and expression can be specified with the –dir and –expr options:

$ efind --dir=/tmp --expr="size>1M and type=file"

efind tries to handle the first two arguments as path and expression. It's valid to run efind the following way:

$ efind ~/git 'type=file and name="CHANGELOG"'

If you want to show the translated arguments without running GNU find use the –print option. To quote special shell characters append –quote:

$ efind . 'iregex=".*\.txt" and writable' --print --quote

efind is shipped with a manpage, of course.

$ man efind

Expression Syntax

A search expression consists of at least one comparison or file flag to test. Multiple expressions can be evaluated by using conditional operators:

OperatorDescription
andIf an expression returns logical false it returns that value and doesn't evaluate the next expression. Otherwise it returns the value of the last expression.
orIf an expression returns logical true it returns that value and doesn't evaluate the next expression. Otherwise it returns the value of the last expression.

Expressions are evaluated from left to right. Use parentheses to force precedence.

The following operators can be used to compare a file attribute to a value:

OperatorDescription
=equals to
>greater than
>=greater or equal
<less than
<=less or equal

A value must be of one of the data types listed below:

TypeDescription
stringQuoted sequence of characters.
numberWhole number.
time intervalTime interval (number) with suffix. Supported suffixes are "minute(s)", "hour(s)" and "day(s)".
file sizeUnits of space (number) with suffix. Supported suffixes are "byte(s)", "kilobyte(s)", "megabyte(s)" and "gigabyte(s)".
file type"file", "directory", "block", "character", "pipe", "link" or "socket".

The following file attributes are searchable:

AttributeDescriptionTypeExample
namecase sensitive filename patternstring"*.txt"
inamecase insensitive filename patternstring"Foo.bar"
regexcase sensitive regular expressionstring".*\.html"
iregexcase insensitive regular expressionstring".*\.TxT"
atimelast access timetime interval1 minute
ctimelast file status changetime interval15 hours
mtimelast modification timetime interval30 days
sizefile sizesize10 megabyte
groupname of the group owning the filestring"users"
gidid of the group owning the filenumber1000
username of the user owning the filestring"john"
uidid of the user owning the filenumber1000
typefile typefile typepipe

Additionally you can test these flags:

FlagDescription
readablethe file can be read by the user
writablethe user can write to the file
executablethe user is allowed to execute the file

Project website

If you want more information or install efind visit the project website.