Linux file lookups are primarily locate, find.
Locate
Locate main Find Fast, real-time, but need to rely on the system file database, and this file database needs to be generated manually: UpdateDB.
Find usage
Real-time, accurate, with many search criteria, it traverses all files in the specified directory to complete the lookup, slow.
Grammar:
Find Find path lookup standard Check to post-processing command
Find path: Default to current directory
Lookup criteria: Default to all files under the specified path
Handling actions: Default to show
Matching Criteria:
-name "filename": Exact Match of file name
File name wildcard:
*: Any character of any length
? :
[]
-iname "filename": File name is not case sensitive. ‘
-regex pattern: File name matching based on regular expressions
-user user: A file that belongs to the user of the owner
-group Group Search by genus
-uid UID
-gid GID
-nouser: Finding files that are not owned by the master
-nogroup: Finding files that are not owned by a group
-type
F: Normal file
D: Catalogue
C: Character device
B: Block device, binary file
L: Link File
P: Pipeline File
S: Socket file
-size
[+|-] #k
#M
#G
Combination condition: "Default is with condition"
- A with conditions
- O or condition
-not Non-conditional
Time
-mtime modification Time
-ctime Change Time
-atime Access Time
[+|-]#
-perm
Mode exact Search
-mode file permissions can fully contain this mode only when the condition is met
/mode any one can match it.
-ok Command {} \; User confirmation is required every time
-exec command {} \;
Common Case Exercises
[Email protected] test]# find/etc/-size +1m | Xargs >>/tmp/etc.largefiles
1. Find the Var directory subordinate to Root and belong to the group mail all Files
[Email protected] test]# find/var/-user root-group mail >/tmp/var.rootmail.file
2. View files in the/usr/directory that do not belong to Root,bin, or student
[[email protected] test]# find/usr/-not \ (-user root-o-user bin-o-user student \)-exec Ls-al {} \;
-rwsr-xr-x. 1 abrt abrt 9856 Jan 2013/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
3. Find files that have been modified in the last week in the/etc/directory and are not part of the root and student users
[Email protected] ~]# find/etc/-mtime-7-a-not \ (-user root-o-user student \)
[Email protected] ~]# find/etc/-mtime-7-not-user root-a-not-user Student
4. Find the file on the current system that does not have a primary or a group and has been accessed for the most recent day, and change its owner group to root
[[email protected] ~]# Find/-atime-1-nouser-nogroup | Xargs chown root:root {} \;
5. Look for files larger than 1M in the/etc/directory and write them to/tmp/etc.arggefile
[Email protected] ~]# find/etc/-size +1m >> largefile
6. Find files with no write permission for all users in the/etc/directory, displaying their details
[Email protected] ~]# find/etc/-not-perm/222
This article is from "Eagle" blog, please be sure to keep this source http://seneagle.blog.51cto.com/1319845/1717799
One of the Linux summaries: common file Lookup methods