Lesson 7 | Finding files |
Objective | Match the find Command's Predicates with Descriptions of their Purpose. |
find
command descends a directory tree from an initial point and locates all files matching a set of criteria. For example, the command
find $HOME –print
$HOME
and prints every file it encounters. The command
find / -user jeremy –print
find / \( -user jeremy –o –user betty\) –print
find / \! –newer /etc/passwd –print
!
needs to be escaped from the shell. –atime +7 –mtime +14
would look for files last accessed more than 7 days ago and last modified more than 14 days ago.
find
is an art in itself, and many other tricks and options are available. Predicate | Meaning |
-o , -a , !
|
OR, AND, NOT respectively |
-atime +/-n -ctime +/-n -mtime +/-n
|
Select files accessed (atime ), modified (mtime ), or changed (ctime ) more (+ ) or less (- ) than n days ago. Changed means modified or had ownership or permission changes.
|
-newer file
|
Select files newer than the specified file. |
-type b/c/d/p/l/f
|
Select files of type block (b ), character (c ), directory (d ), pipe (p ), link (l ), or regular (f ).
|
-user name-group name
|
Select files with specified user or group. |
-name pattern
|
Select files with name matching pattern. Pattern should be enclosed in single quotes to protect it from the shell. |
-perm mode- perm - mode
|
Select files of the given permission mode. To check if a particular bit is set, use –mode , where mode is the numeric value for the desired bit. For example, -004 checks if the "other read" permission bit is set.
|
-print
|
Needed to generate a list of files; otherwise (on some systems), find will find the files, but not print them.
|
find
command's predicates.