File Lookup
grep egrep fgrep Text Lookup
File Lookup:
Locate:
non-real-time, fuzzy matching, lookup is based on the system-wide file database;
# Manually generate file database updatedb;
Find:
Real-time search, precision, slow speed
traverse all files in the specified directory to complete the lookup;
support for many search criteria
Find Find Path lookup criteria lookup to future processing operations
Find path: Default to current directory
Lookup criteria: Default to all files under the specified path
processing operation: default to show printing
Matching Criteria:
-name ' filename ': Exact search for file names
file name wildcard:
*: Any character of any length
?:
[]:
-iname ' filename ': file name matching is case insensitive
-regex PATTERN: Finding based on regular expressions
-user Usernaem:
-group GROUPNAME:
-uid UID
-gid GID User is deleted, belong to group GID number
-nouser: Finding files that are not owned by a group
-type
f: Normal file
D:
C:
B:
L:
P:
S:
-size
+-#k
#M
#G
Combination Conditions
-A and
- O or
-not Non-
find/tmp-not-type-d
-mtime
-ctime
-atime + 5-
[+|-]5----------|-----------> NOW
-mmin
-cmin
-amin
[+|-]# min
-perm:
MODE based on the right to find accurate
-mode: Each permission must match before the line contains the relationship: The file can only be displayed when the whole country is fully inclusive of MODE
/mode: Nine-bit permissions there's a match.
Operation:
-print: Display
-ls: Displays the details of each file in the form of a ls-l like class
-ok:commond \; Confirmation is required for each operation
-exec commad \; No confirmation required
Find./-perm-006-exec chmod o-w {} \;
Find./-type D-ok chmod +x {} \;
Find./-perm-020-exec mv {} {}.new \;
Find./-name "*.sh"-a-perm-111-exec chmod o-x {} \;
Find/etc-sixe +1m-exec Echo {} >>/tmp/etc.largefiles \;
Find/etc-size +1m | Xargs Echo >>/tmp/etc.largefiles
Practice:
1. Find a file with a group of mial that is rooted in the/var directory
Find/var-user Root-group Mail
2. Find files that do not belong to Root,bin or student in the/usr directory
Find/usr-not-user root-a-not-user bin-a-not-user Student
Find/usr-not \ (-user root-o-user bin-o-user student \)
3. Find files that have been modified in the/etc directory for the last week and are not owned by root and student users;
Find/etc-mtime-7-a-not-user root-a-not-user Student
4. Look for files that are not owned or owned by the current system and have been accessed in the most recent day, and change their owner group to root
Find/(\-nouser-o-nogroup \)-a-atime-1-exec chown root:root {} \;
5. Find files larger than 1M in the \etc directory, and write their filenames to the/tmp/etc.largefiles file;
Find/etc-sixe +1m-exec Echo {} >>/tmp/etc.largefiles \;
Find/etc-size +1m | Xargs Echo >>/tmp/etc.largefiles
6. Find files with no write permission for all users in/etc directory, and display their detailed information
Find/etc-not-perm/222-ls
Linux file Lookup--location find command