This link has been bookmarked by 76 people . It was first bookmarked on 08 Oct 2008, by harry palmer.
-
04 Mar 15
-
13 Jan 15
-
The “
\(” and “\)” are just parenthesis used for grouping, and escaped from the shell. The “‑o” means Boolean OR.
-
-
04 Nov 14
-
02 Nov 14
-
One of my favorite of the
findcriteria is used to locate files modified less than 10 minutes ago. I use this right after using some system administration tool, to learn which files got changed by that tool:find / -mmin -10
-
-
07 Aug 14
-
14 Jun 13
-
13 Jun 13
-
You can search for other criteria beside the name. Also you can list multiple search criteria. When you have multiple criteria, any found files must match all listed criteria. That is, there is an implied Boolean AND operator between the listed search criteria.
findalso allows OR and NOT Boolean operators, as well as grouping, to combine search criteria in powerful ways (not shown here.)Here's an example using two search criteria:
-
-
31 May 13
-
30 May 13
-
12 Jun 12
-
25 May 12
-
04 May 12
-
30 Mar 12
-
16 Mar 12
-
findwill search any set of directories you specify for files that match the supplied search criteria. -
The search is recursive in that it will search all subdirectories too.
-
For example
where-to-lookdefaults to.(that is, the current working directory),criteriadefaults to none (that is, show all files), andwhat-to-do(known as thefindaction) defaults to-print(that is, display the names of found files to standard output). Technically the criteria and actions are all known asfindprimaries. -
redirect the error messages so you don't have to see them at all:
-
find / -name foo 2>/dev/null
You can specify as many places to search as you wish:
find /tmp /var/tmp . $HOME -name foo
-
-
29 Jul 11
-
05 Jul 11
Thomas ██████Unix/Linux "find" Command Tutorial: http://bit.ly/k7lETi
-
13 May 11
-
06 May 11
-
07 Feb 11
-
09 May 10
-
28 Apr 10
-
23 Oct 09
-
21 Oct 09
-
06 Oct 09
-
02 Oct 09
-
09 Sep 09
-
02 Sep 09
-
25 Aug 09
-
-
For example:
find . -mtime 0 # find files modified between now and 1 day ago # (i.e., within the past 24 hours) find . -mtime -1 # find files modified less than 1 day ago # (i.e., within the past 24 hours, as before) find . -mtime 1 # find files modified between 24 and 48 hours ago find . -mtime +1 # find files modified more than 48 hours ago find . -mmin +5 -mmin -10 # find files modifed between # 6 and 9 minutes ago
-
find / -type f -mtime -7 | xargs tar -rf weekly_incremental.tar gzip weekly_incremental.tar
will find any regular files (i.e., not directories or other special files) with the criteria
, and only those modified seven or fewer days ago (-type f
). Note the use of-mtime -7xargs, a handy utility that coverts a stream of input (in this case the output offind) into command line arguments for the supplied command (in this casetar, used to create a backup archive).Using the
taroption
is dangerous here;-cxargsmay invoketarseveral times if there are many files found and each
will cause-ctarto over-write the previous invocation. The
option appends files to an archive. Other options such as those that would permit filenames containing spaces would be useful in a-rproduction quality
backup script. -
find / -type f -mtime -7 | xargs tar -rf weekly_incremental.tar gzip weekly_incremental.tar
will find any regular files (i.e., not directories or other special files) with the criteria
, and only those modified seven or fewer days ago (-type f
). Note the use of-mtime -7xargs, a handy utility that coverts a stream of input (in this case the output offind) into command line arguments for the supplied command (in this casetar, used to create a backup archive).Using the
taroption
is dangerous here;-cxargsmay invoketarseveral times if there are many files found and each
will cause-ctarto over-write the previous invocation. The
option appends files to an archive. Other options such as those that would permit filenames containing spaces would be useful in a-rproduction quality
backup script. -
is a Gnu extension. On a modern, POSIX version of-maxdepthfindyou could use this:find . -path './*' -prune ...
On any version of
findyou can use this more complex (but portable) code:find . ! -name . -prune ...
which says to
prune
(don't decend into) any directories except
..
-
-
13 Aug 09
-
01 Jul 09
-
29 May 09
-
23 Apr 09
-
16 Apr 09
-
05 Apr 09
-
25 Mar 09
-
17 Feb 09
Valent TurkovicThe find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other
-
03 Feb 09
-
21 Jan 09
-
01 Dec 08
-
22 Nov 08
-
08 Oct 08
-
Locating Files:
The
findcommand is used to locate files on a Unix or Linux system.findwill search any set of directories you specify for files that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria. The search is recursive in that it will search all subdirectories too. The syntax looks like this:find where-to-look criteria what-to-do
All arguments to
findare optional, and there are defaults for all parts. (This may depend on which version offindis used. Here we discuss the freely available GNU version offind, which is the version available onYborStudent.) For examplewhere-to-lookdefaults to.(that is, the current working directory),criteriadefaults to none (that is, show all files), andwhat-to-do(known as thefindaction) defaults to-print(that is, display found files to standard output).
-
-
07 Oct 08
-
17 Sep 08
-
26 Aug 08
-
07 Aug 08
-
27 Jul 08
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.