find [-H] [-L] [-P] [-Olevel] [-D help| tree| search| stat| rates| opt| exec] [ route ] [ expression ]

find It's the command to find the file , It's not about the content of the file

The default path is the current directory ; The default expression is –print

An expression may consist of the following components : The operator 、 Options 、 Test expressions and actions .

( One ). Options

-H、-L、-P Three options are mainly used to handle symbolic links

-H Means to follow only the symbolic links specified on the command line

-L Means to follow all the symbolic links

-P Is the default option , Does not follow the symbolic link

-O Enable query optimization , Followed by a number ( There are no spaces ).0 Equate to 1;1 Default optimization level , Corresponding to traditional behavior . Expressions are reordered , So that it's only based on the file name ( for example -name and -regex) The first test to perform ;2 whatever -type or -xtype Tests are performed after any test based on a file name , But in any need inode( The index node ) Before testing information ;3 At this optimization level , The full cost based query optimizer is enabled . The order of the tests was modified , In order to perform the cheap ( fast ) test , And perform more expensive tests later if necessary .

-D Used to display debug information .help Explain debugging (-D) Options ;tree Displays the original and optimized form of the expression tree ;search Browse the tree in detail ;stat Use stat and lstat The system calls to check the print information of the document ,find The program tries to minimize this call ;rates Print a summary , Represent each predicate( The predicate ?) The frequency of success or failure ;opt Print diagnostic information related to optimizing the expression tree , see also -O Options ;exec Display and -exec,-execdir,-ok and -okdir Diagnostic information

( Two ). expression

(1). The operator

Priority decrement ; If no specification is made, it will be used by default -and(EXPR=expression= expression )

(EXPR) Brackets have the highest priority , First, evaluate the values in brackets

! EXPR Yes EXPR The value of the expression is negated

-not EXPR ditto , however POSIX I won't support it

EXPR1 EXPR2 Without any operators , It's equivalent to adding and, That is, and operation , Both expressions have the value true The whole talent true. First pair expr1 Expression evaluation , if false, It's not right expr2 evaluation .

EXPR1 -a EXPR2 ditto

EXPR1 -and EXPR2 ditto , however POSIX I won't support it

EXPR1 -o EXPR2 Express expr1 and expr2 The sum of the values of two expressions , Only one of the left and right values true, The whole expression is true. First pair expr1 Expression evaluation , if true, It's not right expr2 evaluation .

EXPR1 –or EXPR2 ditto , however POSIX I won't support it

EXPR1,EXPR2 Comma expression .expr1 and expr2 Will evaluate , But only return to expr2 Value ,expr1 The value of is discarded .

(2). Options

Location options

-daystart From the beginning of the day , Not from 24 Hours ago , computing time

-follow Do not retrieve symbolic links . Implication -noleaf, Discard parameters , use -Linux Instead of

-regextype Set the type of regular expression , Default type emacs,posix-awk、posix-basic、posix-egrep and posix-extended

Common options

-depth Start from the deepest subdirectory under the specified directory

--help help

-maxdepth <LEVELS( Directory level )> Set the maximum directory level

-mindepth <LEVES( Directory level )> Set the minimum directory level

-mount Do not cross the file system when looking up mount spot ( Mount point ), And -xdev identical

-noleaf Regardless of the directory, at least two hard links need to exist

--version Display version information

-xdev Do not enter a directory on another file system

-ignore_readdir_race Generally speaking, if you fail to count a file, you will throw a err, If you turn on this option , The error message is masked

-noignore_readdir_race close -ignore_readdir_race effect

(3). Test expression

+N It's better than N Big

-N It's better than N Small

N Is precisely N

All of the following N All represent the above -N,+N and N

-admin <N( minute )> The last access to the file was in N Minutes ago

-anewer <FILE( References )> The most recent access to a reference document is more than file It's going to be late . If in the command line -follow stay -anewer Before ,( Only in this case )-anewer Will receive -follow Influence

-atime <N(24 Hours )> The last access to the file was in N*24 Hours ago

-cmin <N( minute )> The last change to the file status was in N Minutes ago

-cnewer <FILE( References )> The most recent modification to the status of the reference document File It's late to revise . If in the command line -follow stay -cnewer Before ,( Only in this case )-cnewer Will receive -follow Influence

-ctime <N(24 Hours )> The last change to the file status was N*24 Hours

-empty The file is empty , It can be a normal file or directory

-false Always false

-fstype <TYPE( File system type )> lookup TYPE Type of file system . These file system types are usually available in /etc/fstab Find , The configuration file contains information about the file system in the system . Valid file system types in different versions of Unix It's different ; some Unix The incomplete list of file system types in is like this :utf,4.2,4.3,nfs,tmp,mfs,S51K,S52K. You can use -printf add %F To see your file system type .

-gid <N( Group ID )> Find files that match the group ID

-group <GNAME( The name of the group )> Find files that match the group name ( Allow group ID )

-ilname <PATTERN( Template Styles )> And -lname similar , But matching is case insensitive

-iname <PATTERN( Template Styles )> And -name similar , But matching is case insensitive

-inum <N(inode Number )> Look for the specified inode Numbered documents

-ipath <PATTERN( Template Styles )> And -path similar , But matching is case insensitive .( And -iwholename identical , Some system prompts are discarded )

-iregex <PATTERN( Template Styles )> And -regex similar , But matching is case insensitive

-iwholename <PATTERN( Template Styles )> And -wholename similar , But not case sensitive

-links <N( Number of connections )> Find a match for the specified N A hard linked file

-lname <PATTERN( Template Styles )> Appoint PATTERN The string is a template style for finding symbolic links , Metacharacters don't correct ’/’ and ’.’ Do the processing

-mmin <N( minute )> The last modification time of file data is N Minutes ago

-mtime <N(24 Hours )> The last modification of file data is in N*24 Hours ago

-name <PATTERN( Template Styles )> Find files by file name . Appoint PATTERN The string is the template style of the lookup file , Metacharacters ’*?[]’ Does not match the beginning of the file name . Use -prune To skip a directory and its files . see -path Examples in the description of

-newer <FILE( A reference document or catalogue )> The last modification to the file is better than FILE It's going to be late . If in the command line -follow stay -newer Before ,( Only in this case )-newer Will receive -follow Influence

-nouser Find files that do not belong to the local host user ID

-nogroup Find files that do not belong to the local host group ID

-path <PATTERN( Template Styles )> Appoint PATTERN The string is the template style of the lookup file , Metacharacters don't correct ’/’ and ’.’ Do the processing

-perm [ +-]MODE Find files by file permissions . Find the specified permission value ( Or symbols ) The file of .MODE It's just to meet the requirements of the authority ;-MODE Yes, the set permissions must satisfy , There are no set permissions , There can be no ;+MODE It's the three kinds of permissions that the three types of users have , As long as any one of the users has any one permission ( Partial satisfaction ), There are no set permissions , There can be no .+MODE And later /MODE identical

-regex <PATTERN( Template Styles )> Appoint PATTERN The string is the template style of the lookup file , It's a match on the path .

-readable Match readable files

-writable Match writable files

-executable Matching executable files

-wholename <PATTERN( Template Styles )> See -path

-size N[ bcwkMG] Find a file with the specified file size ,1 byte c,2 byte w, block (512 byte )b kilobytes k, Megabytes M, Gigabyte G.

-true Always true

-type [ bcdpflsD] Search by file type .f Ordinary documents ,l A symbolic link ,d Catalog ,c Character device ,b Block device ,s Socket ,p name pipes (FIFO),D(Solaris hold )

-uid <N( User identification number )> Find a file that matches the specified user ID

-used <N( Days )> The last access to the lookup file is the last modification N Days later

-user <UNAME( Owner name )> Find a file that matches the name of the specified owner

-xtype [ bcdpfls] And -type similar , It's just for symbolic links

-context CONTEXT Secure file context matching pattern ( be limited to SELinux)

(4). action

-delete Delete , Successfully returns true, Failure to return err Information . If the deletion fails ,find The final exit code is not 0, Use -delete Turn on automatically -depth Options

-exec COMMAND ; perform COMMAND. All the results found will be provided as parameters to the command , Until I met someone with ';' So far as the parameters of the composition are concerned . In the parameters of the command , character string '{}' Will be replaced with the name of the file being processed . be-all '{}' Will be replaced , Not just in a single parameter . Some versions of find It's not like that . These parameters may need to use '\' To escape or bracket , Prevent it from being unfolded . The command is executed from the start Directory .

( Be careful : The general usage is -exec COMMAND {} \;)

-exec COMMAND {} + yes -exec A variant of action execution , Execute the specified command for the selected file , But the command line is built by adding each selected file name to the end . The total number of commands invoked will be far less than the number of matching files . The way the command line is built is similar to xargs It's built in much the same way as the command line . Only one is allowed in the order "{}" Example . This command is executed from the starting directory .

-execdir COMMAND ; And -exec similar , But the specified command starts from the subdirectory , Include matching files

-execdir COMMAND {} + And -exec similar , But the specified command starts from the subdirectory , Include matching files

-fls FILE return true; similar -ls But like -fprint Write like that file

-fprint FILE return true; Print the full name of the file to the file file in . If you run find when file non-existent , Then it will be created . If it exists , It will be overwritten . file name '/dev/stdout' and '/dev/stderr' Special treatment ; They refer to standard output and standard error output respectively . Output files are always created .

-fprint0 FILE return true; similar -print0 But like -fprint Write like that file

-fprintf FILE FORMAT return true; similar -printf But like -fprint Write like that file

-ls return true List... In the standard output 'ls -dils' View the files

-ok COMMAND ; similar -exec But I'll ask the user first ( In standard output ); If the response is not 'y' or 'Y' At the beginning, it doesn't run COMMAND It's going back to false;

-okdir COMMAND similar -ok But start with subdirectories  

-print return true; Print the full name of the file in standard output , And then a newline

-print0 return true; Print the full name of the file in standard output , Then one null character . This allows you to deal with find The output of the program can correctly understand the file name with a newline character .

-printf FORMAT return true; Print on standard output FORMAT, explain '\' Escape and '%' Instructions . Field width and precision can be like C function 'printf' That's how to specify . And -print The difference is ,-printf No new line is added at the end of the string .( See the fifth item for escape and instruction )

-prune If not given -depth Then return to true, Do not enter current directory ( Exclude the current directory ). If given -depth Then return to false, There is no effect .

-quit Quit immediately . No child processes will remain running , But no more paths specified on the command line are processed

(5). Escape and instruction

\a The warning bell

\b Back off

\c Stop exporting in the current format immediately , Refresh output device

\f End of form

\n New line

\r enter

\t level tab

\v vertical tab

\\ Output itself '\'

\NNN ASCII Encoding is NNN( octal ) The characters of

%% Output itself '%'

%a The last time the file was accessed . The format is C function 'ctime' Format of return value .

%Ak The last time the file was accessed . Format to k Appoint , But '@' Or is it C function 'strftime' The command format of . The available values are listed below , Some are not available on all systems .

                      H Hours (00..23)
                      I Hours (01..12)
                      k Hours ( 0..23)
                      l Hours ( 1..12)
                      M minute (00..59)
                      p District morning (AM) Or afternoon (PM)
                      r Time ,12 hourly (hh:mm:ss [AP]M)
                      S second (00.00 .. 61.00). There's a fractional part .
                      T Time , 24 hourly (hh:mm:ss)
                      + Date and time , With '+' Separate , for example '2004-04-28 + 22:22:05.0'. This is a GNUplot Expand . The time is given in the current time zone ( It may be set TZ The impact of environmental variables ). The seconds field contains a decimal part
                      X Time representation of language environment (H:M:S)
                      Z The time zone ( for example EDT), Or if no time zone is determinable , Is empty
                     Date fields:
                      a  District abbreviation workday name (Sun..Sat)
                      A Area full weekday name , Variable length (Sunday..Saturday)
                      b Abbreviated name of the month (Jan..Dec)
                      B District full month name , Variable length (January..December)
                      c The date and time of the district (Sat Nov 04 12:02:33 EST 1989). Format and (3) identical , So in order to maintain compatibility with this format , There is no decimal part in the seconds field
                      d What day of the month (01..31)
                      D date (mm/dd/yy)
                      h and b identical
                      j What day of the year (001..366)
                      m month (01..12)
                      U The week of the month , Sunday is the first day of the week (00..53)
                      w  What day (0..6)
                      W The week of the year , Monday is the first day of the week (00..53)
                      x The date representation of the language environment (mm/dd/yy)
                      y The last two digits of the year (00..99)
                      Y year (1970...)
 

%b The file size is 512 In byte blocks ( rounding )

%c File status last modified . The format is C function 'ctime' Format of return value

%Ck  File status last modified . Format to k Appoint , similar %A

%d The depth of the file in the tree ;0 Indicates that the file is a command line parameter

%f Remove the file name of the previous Directory ( It's just the final ingredient )

%F The type of file system where the file is located ; This value can be -fstype used .

%g The group name of the file , If a group doesn't have a name, it's a numeric group ID.

%G Groups of files in digital form ID

%h The directory part in front of the file name ( Remove only the final ingredients )

%H Based on the command line parameters of the found file

%i Of documents i Node number (16 Base number )

%k The file size is 1KB In units of ( rounding )

%l The goal of symbolic links ( If the file is not a symbolic link , So the result is an empty string )

%m Permission bit of file (8 Base number )

%n Number of hard links to files

%p file name

%P file name , Remove the name section of the command line argument based on the found file

%s file size , In bytes

%t Last modification time of document , The format is C function 'ctime' Format of return value

%Tk The last modification time of the file . Format to k Appoint , similar %A

%u The user name of the file , If a user doesn't have a name, it's a digital user ID

%U The digital form of the file for the user ID