First, File search:
Find eligible files on the file system;
File Lookup: Locate, find
Non-real-time lookup (Database lookup): Locate
Real-time Find: Find
Locate
Relies on pre-built indexes, which are built automatically when the system is idle (recurring tasks), manually updating the database (UpdateDB), and the indexing process requires traversing the entire root file system, consuming resources very much;
Working characteristics:
Fast search speed;
Fuzzy search;
Non-real-time lookup;
Grammar:
Locate KEYWORD
Find
Real-time Find tool to complete file search by traversing the file system under the specified path;
Working characteristics:
The search speed is slightly slower;
Accurate search;
Real-time search;
Grammar:
Find [OPTION] ... [Find Path] [Search Criteria] [Handling Action]
Find path: Specify the target path, default to the current directory;
Search criteria: The specified search criteria can be file name, size, type, permissions and other standards, the default is to find all the files under the specified path;
Handling actions: What to do with the eligible files; default output to the screen;
Search criteria:
Search by file name:
-name "file name": Support using Glob *,?, [], [^]
-iname "file name": Letter case insensitive
-regex "pattern": matches the entire file path string with pattern, not just the file name;
According to the genus, the genus Group looks for:
-user USERNAME: Find files belonging to the owner of the specified user;
Group GRPNAME: Find files that belong to a specified group;
-uid UserID: Find the file that belongs to the UID number specified by the owner;
-gid GroupID: Finds files belonging to the specified GID number;
-nouser: Find files that are not owned by the master;
-nogroup: Find files without a group;
Find by File type:
-type Type:
F: Normal file
D: Catalog file
L: Symbolic Link file
S: Socket file
B: Block device files
C: Character device file
P: Pipeline File
Combination conditions:
With:-A
Or:-O
Non:-not,!
! A-a! B =! (A-o B)
! A-o! B =! (A-a B)
Case:
Find out the/tmp directory, the owner is not root, and the file name is not fstab files;
Find/tmp \ (-not-user root-a-not-name ' fstab ' \)-ls
Find/tmp-not \ (-user root-o-name ' fstab ' \)-ls
Depending on the file size, look for:
-size [+|-] #UNIT
Common units: K, M, G
#UNIT: (#-1, #)
-#UNIT: [0,#-1]
+ #UNIT: (#,oo)
Based on time stamp:
Take "Day" as the unit;
-atime [+|-]#,
#: [#,#+1]
+#: [#+1,oo]
-#: [0,#]
-mtime
-ctime
In "Minutes" units:
-amin
-mmin
-cmin
Search by permissions:
-perm [+|-]mode
MODE: Exact permission match
+mode: The permission of any class (U,g,o) object can only be matched by one match;
-mode: Each type of object must have a permission standard assigned to it at the same time;
Handling actions:
-print: The default processing action, display to the screen;
-ls: Similar to executing the "ls-l" command on the found file;
-delete: Delete the found file;
-fls/path/to/somefile: Long format information for all files found is saved to the specified file;
-ok COMMAND {} \; Executes commands specified by command on each file found, and requires user confirmation interactively before executing commands for each file;
-exec COMMAND {} \; Executes commands specified by the command for each file found; {}: Used to refer to the file name itself;
Note: When find passes the found file to the command specified later, it finds all eligible files once passed to the following command;
Some commands cannot accept too many arguments, at which point the command execution may fail, and another way to circumvent this problem: find | Xargs COMMAND
Practice:
1. Find the main root of the/var directory, and belong to all files or directories of mail;
# find/var-user Root-group Mail
2. Find all files or directories that do not belong to root, bin, or Hadoop under the/usr directory;
# find/usr-not-user root-a-not-user bin-a-not-user Hadoop
# find/usr-not \ (-user root-o-user bin-o-user hadoop \)
3, look for/etc directory in the most Monday weeks of its content has been modified, but also the main is not root, nor is the file or directory of Hadoop;
# find/etc-mtime-7-a-not-user root-a-not-user Hadoop
# find/etc/-mtime-7-a-not \ (-user root-o-user hadoop \)
4. Find files or directories on the current system that are not owned by the master or group and have been visited in the last week;
# Find/-nouser-a-nogroup-a-atime-7
5. Find all files that are larger than 1M and type ordinary files in/etc directory;
# find/etc-size +1m-type F
6, look for all the users in/etc directory do not have permission to write files;
# find/etc-not-perm/222
7. Find at least one class of users who do not have permission to execute files in/etc directory;
# find/etc-not-perm-111
8, find/etc/init.d directory, all users have execute permission, and other users have write permission files;
# find/etc/init.d-perm-113
Summary of file suffixes:
Common suffix names:
*.php------is a file that can be interpreted with a PHP language interpreter and opened with a browser;
*.so-------This class is a library file;
*.doc *.OBT--------This is the file that OpenOffice can open;
. bz2------Bzip2 Compressed Files
. GZ------Gzip Compressed file
. tar------Tar package file (the package file is not a compressed file)
. TBZ------Tar package and compress files with bZIP
. tgz-----Tar package and gzip compressed files
. au-----Audio file
. gif-----GIF image files
. html/.htm-----HTML file
. jpg-----JPEG image files
. PDF------Electronic documents (in PDF format)
. png-----PNG image files
. PS------POSTSCINPT file (print format file)
. txt------Plain text files
. wav-----Audio files
. XPM-----Image files
. conf-------Configuration file
. lock-------Lock file (used to determine if a file or device is being used)
. RPM------Redhatpackage.manager File (Suite package or package)
. c-------C source program code files
. cpp------C + + source program code files
. h-------header files for C or C + + programs
. o------Program target file
. pl------Perl Script file
. So-----class library files
Linux Basics-day Sixth