Linux Find File (directory) lookup

Source: Internet
Author: User
Tags glob

1 File Lookup:2 find eligible files on the file system;3 4 File Lookup: Locate, find5 non-real-time lookup (Database Lookup): Locate6 Real-time find: find7 8 Locate:9 dependent on pre-built indexes; The index is built automatically when the system is idle (periodic tasks); Manually update the database (updatedb);Ten  One the index construction process needs to traverse the whole root file system, consuming resources extremely; A  - Working characteristics: - fast search speed; the fuzzy search; - non-real-time lookup; -  - Locate KEYWORD +  - Find: + Real-time Find tool to complete file search by traversing the file system under the specified path; A  at Working characteristics: - The search speed is slightly slower; - accurate search; - real-time search; -  - Syntax: in find [OPTION] ... [Find Path] [Search Criteria] [Handling Action] - Find path: Specify the target path, default to the current directory; to 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; -  the Search criteria: * Search by file name: $-name"file name": Supports the use of GlobPanax Notoginseng*, ?, [], [^] --iname"file name": letter Case insensitive the  +-regex"PATTERN": Matches the entire file path string with pattern, not just the file name; A  the 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: Finds the file that belongs to the specified UID number; --gid GroupID: Finds files belonging to the specified GID number; -  the-Nouser: Find files that are not owned by the master; --Nogroup: Find files without a group;Wuyi  the Find by file type: --Type type: Wu f: Normal file - d: Catalog file About L: Symbolic Link file $ s: Socket file - B: Block device files - C: Character device file - P: Pipeline file A  + Combination conditions: theWith:-a -Or:-o $Non-:- not, ! the  the! A-a! B =! Ao B) the! A-o! B =! Aa B) the  -Findtmp directory, the owner is not root, and the file name is not fstab files; inFIND/TMP \ (- not-user Root-a- not-name'Fstab'\) -ls theFind/tmp- not\ (-user root-o-name'Fstab'\) -ls the  About depending on the file size, look for: the-size [+|-]#UNIT the Common units: K, M, G the  +                             #UNIT: (#-1, #] 3k----(2,3) --#Unit:[0,#-1] 3k----[0,2] the+#UNIT: (#,oo) 3k = = (3,+oo)Bayi  the based on time stamp: the take "Day" as the unit; --atime [+|-]#,   -                                 #: [#,#+1] 3 [3,4] the+#: [#+1,oo] [4,oo] the-#: [0,#] [0.3] the-Mtime the-CTime -  the in "minutes" units: the-Amin the-Mmin94-Cmin the  the Search by permissions: the-perm [+|-]mode98 MODE: exact permission match About+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;101 102 Handling actions:103-Print: The default processing action, display to the screen;104-ls: Similar to executing "LS-for found file"l "ORDER; the-Delete : Deletes the found file;106-fls/path/to/somefile: Long format information for all files found is saved to the specified file;107-OK command {} \; Executes commands specified for each file found ;108 user Confirmation is requested interactively before each file executes the command;109-execcommand {}\; executes commands specified for each file found ; the {}: Used to refer to the file name itself;111  the Note: When find passes the found file to the command specified later, it finds all eligible files once passed to the following command;113 Some commands cannot accept too many arguments, at which point the command execution may fail, and another way to circumvent this problem: theFind |Xargs COMMAND the  the Practice:1171. Find/The var directory is subordinate to root and all files or directories belonging to the group Mail;118                 #find/var-user Root-group Mail119  -2. Find/all files or directories in the USR directory that do not belong to root, bin, or Hadoop;121                 #find/usr-not-user root-a-not-user bin-a-not-user Hadoop122                 #find/usr-not \ (-user root-o-user bin-o-user hadoop \)123 1243. Find/etc directory in the most Monday weeks its content has been modified, while the owner is not root, nor is it a Hadoop file or directory; the                 #find/etc-mtime-7-a-not-user root-a-not-user Hadoop126                 #find/etc/-mtime-7-a-not \ (-user root-o-user hadoop \)127  -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;129                 #Find/-nouser-a-nogroup-a-atime-7 the 1315. Find/all files that are larger than 1M in the ETC directory and are of the normal file type; the                 #find/etc-size +1m-type F133 134 1356. Find/all users in the ETC directory do not have permission to write files;136             #find/etc-not-perm/222137 1387. Find/at least one type of user does not have permission to execute files in etc directory;139             #find/etc-not-perm-111 $ 1418. Find/etc/INIT.D directory, all users have execute permissions, and other users have write permission files;142             #find/etc/init.d-perm-113

File Lookup: Find eligible files on the file system;
File Lookup: Locate, find non-real-time lookup (Database lookup): Locate real-time lookup: Find
Locate: relies on pre-built indexes, which are built automatically when the system is idle (periodic tasks); Manually update the database (UPDATEDB);
The index construction process needs to traverse the whole root file system, consuming resources extremely;
Working characteristics: Fast Search, fuzzy search, non-real-time search;
Locate KEYWORD
Find: Real-time Find tool to complete file search by traversing the file system under the specified path;
Job Characteristics: Search speed is slightly slow, accurate search; real-time search;
Syntax: Find [OPTION] ... [Find Path] [Search Criteria] [Processing action] Find the 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 defaults to find all the files under the specified path, processing actions: What to do with the conditions of the file, the default output to the screen;
Search criteria: Search by FileName:-name "file name": Support using glob*,?, [], [^]-iname "file name": Case-insensitive letter
-regex "pattern": matches the entire file path string with pattern, not just the file name;
Search by Genus:-user USERNAME: Finds files that belong to the specified user; Group GRPNAME: Finds files belonging to the specified group;
-uid UserID: Finds the file that belongs to the specified UID number;-gid GroupID: Finds files belonging to the specified GID number;
-nouser: Find files that are not owned by the master;-nogroup: Find files that are not part of the group;
Find by file type:-type type:f: Normal file D: Directory file L: Symbolic link File s: Socket file B: Block device file C: Character device file P: Pipe file
Combination conditions: With:-A or:-O non:-not,!
! A-a! B =! (A-o B)! A-o! B =! (A-a B)
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 ' \)-lsfind/tmp-not \ (-user root-o -name ' fstab ' \)-ls
Find by File size:-size [+|-] #UNIT常用单位: K, M, G
#UNIT: (#-1, #] 3k----(2,3]-#UNIT: [0,#-1] 3k----[0,2]+ #UNIT: (#,oo) 3k = = (3,+oo)
Based on time stamp: in "Day" unit;-atime [+|-]#, #: [#,#+1] 3 [3,4] +#: [#+1,oo][4,oo]-#: [0,#] [0.3]-mtime-ctime
In minutes:-amin-mmin-cmin
Lookup According to permissions:-perm [+|-]modemode: Exact permissions match +mode: the permission of any class of (U,g,o) object can only be one match;-mode: Each class of objects must have the same permission criteria assigned to it;
Processing action:-print: Default processing action, display to screen;-ls: Similar to executing "ls-l" command on found file;-delete: Delete 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 interactively asks for user confirmation 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 to be passed to the following command one at a time, and some commands cannot accept too many arguments, at which point the command execution may fail; Another way to circumvent this problem: find | Xargs COMMAND
Exercise: 1, find the/var directory subordinate to the main root, and belong to the group mail all files or directories; # 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, find in/etc directory in the most Monday weeks its content has been modified, and is not the root of the master, 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 in the/etc directory and are of normal file type; # find/etc-size +1m-type F

6. Find files with no write permission for all users in/etc directory; # 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

Linux Find File (directory) lookup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.