|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
Softpanorama Search
|
Find development processes thru several generations and each left certain mark on its ability to use regular expressions. As of August 2009 it still cannot use Perl regular expression, though.
find /etc -name '*.conf'
Note: To ignore a subtree you can use -prune .
In the context of the tests -path,
-wholename, -ipath
and -wholename, a path is
consists of all the directories traversed from find's start
point to the file being tested, followed by the base name of the file itself.
These paths are often not absolute paths; for example
cd /tmp
mkdir -p foo/bar/baz
find foo -path foo/bar -print foo/bar # first find command
find foo -path /tmp/foo/bar -print # the second find command (prints nothing)
find /tmp/foo -path /tmp/foo/bar -print /tmp/foo/bar # the third find command
Notice that due to search starting point foo the second find command prints nothing, even
though /tmp/foo/bar exists.
Unlike file name expansion on the command line, a * in the pattern will match both / and leading dots in file names:
$ find . -path '*f'
./quux/bar/baz/f
$ find . -path '*/*config'
./quux/bar/baz/.config
Type of regular expression can be specified with option -regextype. In best GNU traditions you need to select from several option only half of which are useful
* Matches any zero or more characters. ? Matches any one character. [string] Matches exactly
one character that is a member of the string string.
This is called a character class. As a shorthand,
string may contain ranges, which consist of two characters
with a dash between them. For example, the class [a-z0-9_]
matches a lowercase letter, a number, or an underscore. You
can negate a class by placing a !
or ^ immediately after
the opening bracket. Thus, [^A-Z@]
matches any character except an uppercase letter or an at sign.
\ Removes the special meaning of the character
that follows it. This works even in character classesSee Regular Expressions for more information on the regular expression dialects...
The regular expression itself can be specified using -regex option (or -iregex option which ignores case). You must quote patterns that contain metacharacters to prevent the shell from expanding them itself. Double and single quotes both work; so does escaping with a backslash.
Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Disclaimer:
Created: May 16, 1997; Last modified: August 25, 2009