Linux file Lookup

Source: Internet
Author: User

Linux file Lookup Find
File Lookup
Locate
File lookup: Finding eligible files on a file system relies on a pre-built Index library query system on the prebuilt file index database/VAR/LIB/MLOCATE/MLOCATE.DB system automatically implemented, periodic tasks. Manually created with a new database (UpdateDB, very consuming system resources) use with caution!
Operating characteristics:
     Find Fast      Fuzzy Lookup      non-real-time lookup, may have a file that has changed or does not exist       is a global lookup that is not for a path lookup. For mlocate.db  this data find     locate [option] ... Pattern...            -b matches only the base name in the path              -C statistics on the total number of eligible documents              -r using the basic regular expression         locate  passwd              The default search is, Find the passwd as long as it exists in the path.             -b  only matches the base name section.             -r  using regular Expressions                  locate -br passwd$   Find the passwd end of the base name in the file [[email protected] ~]# locate -br ^passwd$/etc/passwd/etc/pam.d/passwd Note: Search for keywords without quotes 
Find command
Real-time Lookup tool, which iterates through the file system hierarchy at the specified starting path to complete the file Lookup work feature: Find faster and more accurate find real-time find finding [OPTIONS] [Find starting path] [find] [processing action] Find start path: Specify the specific search target starting route The default is the current directory lookup criteria: The specified lookup criteria, which can be based on the file name, size type.    dependencies, permissions, timestamps, and other standards. Defaults to finding all files under the specified path (effects like LS) processing actions: Actions made to match the find criteria, such as delete, default output to standard output
Search criteria:
Expressions: Options and test composition tests: The result is usually a Boolean (true,false)-name "pattern" lookup based on the base name-iname "pattern" ignores the case PATTERN--->glob-style wildcard characters * ? [] [^] ... *-regex PATTERN finding file matches based on regular expressions is the entire path, not the base name (not many)

Combination test:

With:-A defaults to combinatorial logic (multiple conditions are met at the same time) or:-O (or) satisfies one of the conditions can be non:-not,! Conditional inversion
Options

Search according to the genus of the file

~] #find/tmp-user username-user username: Find files that belong to the specified user (UID)-group GRPNAME: Find files belonging to Group (GID)-uid UserID: Find the owner for the specified The UID number of the file-gid GroupID: Finds files belonging to the specified GID number-nouser: Find file with no master-nogroup: Find files without a group note: The user is deleted, the group is deleted, the files that are not the owner and the group are left only the UID and GID are not the owner and Group available-ls View

Find based on the type of file

-type Type F normal file D directory file l Symbolic link file B block device C character device p pipe file s Socket file example: [[email protected] ~]# Find/home/yangyouwei -type F

Find criteria

     combination conditions:         and:-a     are the default          or:-o         non:-not,  !         De Morgan Law:              (non-P)   or (non-Q) =  (p  and Q)               (non-P)   and (non-Q)  =  non (p  or q)      example:         ! a -a ! b = ! (a -o b)         ! a -o ! b = ! (a -a b) 

find Example

find -name snow.png     search for a file named Snow.png find -iname snow.png      Search for names Snow.png, Snow.png, and Snow, in a case-insensitive manner. PNG and so on file find / -name  "*.txt" find /var –name  "*log*" find-userjoe - Groupjoe Search for files owned by user joe  and group Joe Find -user joe -not -group joefind -user  joe -o -user janefind -not \ ( -user joe -o -user jane  \) find / -userjoe -o -uid500     find files in the/tmp directory where the owner is not root and the file name does not start with F         find /tmp\ ( -not -user root -a - not -name  ' f* '  \)  -ls        find /tmp-not  \ ( -user root -o -name  ' f* '  \)  –ls

Note-ls Action is the action on the last search condition. Parentheses to add escape characters

Exclude Directory

Example: Find all other conf suffix files under/etc/, except the/ETC/SANE.D directory Find/etc-path '/etc/sane.d '-a-prune-o-name ' *.conf '-print

Find by File size

            -size [+|-] #UNIT       #为指定大小的数字                   Common units:k.m.g   Capital                   #UNIT-----(#-1,# "                 -#UNIT----"0,#-1)                  + #UNIT----(#, Infinity "  -0---------#-1----#----#+1-------> Infinity-    |          |      |     |          Search by Timestamp               in days   the day of the current time              -atime [+|-]#                 +#-------(x>=#+1)   a few days ago  x+1                  -#------(x<#)       days before   Does not include x until now                 #----- -(#<=x<#+1)   within  24 hours of the first day    <------------x+1----x----x-1----------0-                  |      |     |            |            -mtime             -ctime              &nbsp per minute;               -amin                 -mmin                 -cmin

find

based on file permissions

    -perm [+|-] mode    mdoe: Exact Match          MODE  three-digit permissions such as 664,755,222...    +mode for any class of users (U,g, O) The permissions of any one of the users eligible to meet both conditions         find ./ +222  any class with as long as the own write can         find ./ +621  Master has read or write or group has written or other people have executive authority three conditions meet one of the conditions     0  is not interested in     -mode each of the rights of each class of users meets the criteria at the same time          find ./ -222  indicates that each bit is less than or equal to 2         find ./ -666  includes 666,650,550,111 but does not include 766find -perm  755 matches a file with a permission pattern that happens to be 755. As long as anyone has write permission, find -perm +222 will match only when everyone has write permission, find -perm - 222 matches only if other people (other) have write permissions, find -perm -002 matches

Handling actions:

-print output to standard output; The default action-ls is similar to performing a "ls-l" on the found file-delete deleting the found file (with caution)-fls/path/to/somefile find long format information to file saved to the specified file-ok COMMAND {    }\; The user is required to confirm-exec command {}\ for each time the found file executes commands represented by the Commands are executed for each file that is found, but no user acknowledgement is required: Some commands cannot receive too long arguments at this point the execution of the command fails. Workaround, Find | Xargs COMMAND

find Example

    find -name  "*.conf"  -exec cp {} {}.org \;          Backup configuration file, Add. orig This extension     find /tmp - ctime+3 -user joe -ok rm {} \;         Tip Delete a temporary file for Joe that is older than 3 days     find ~ -perm -002 -exec chmodo -w  {} \;         find files in your home directory that can be written by other users      find /data –type f -perm 644 -name  "*.sh"  –exec chmod 755  {} \;    find /home –type d -ls 

practice

1. Find all files in the/var directory that are subordinate to root and belong to the group Mail [[Email protected] ~]# find /var -user root &NBSP;-GROUP&NBSP;MAIL/VAR/SPOOL/MAIL2, find all files that are not root, LP, GDM under the/var directory  find /var -not \ (  -user root -o -user lp -o -user gdm \) &NBSP;-LS3, Find/ The contents of the Var directory have been modified in the last week, and the owner is not root or postfix file find -mtime  -7 -not \ ( -user  root -o -user postfix \) 4. Find files on the current system that do not belong to the master or group, and have been visited in the last week [[email protected] ~]#  find \ ( -nouser -o -nogroup \)  -a -atime -75, Find/ All files of the ETC directory that are larger than 1M and are of a normal file [[Email protected] ~]# find /etc -size +1m -type  f6, find files with no write permission for all users in/etc directory [[email protected] ~]# find  /etc/ -not - perm /2227, find at least one class of users who do not have permission to execute files FIND&NBSP;/ETC&NBSP;-PERM&NBSP;/666&NBSP;-LS8, find/etc/ INIT.D directory, all users have execute permissions, and other users have write permission to the file find /etc/rc.d/init.d/ -perm  -110 -perm /002 


Linux file 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.