Article Source: http://www.chinaz.com/server/2009/0807/85796.shtml
Today, I accidentally saw the find command in Linux, and then I searched for the content on the Internet. In order to help you learn the reference, I will summarize it, the result of one morning's work!
The first is the find Syntax:
Find [start Directory] search for conditional operations
There is also a way to express it: Find path option [-exec command {} \;]
Because the find command will perform recursive search on the files and Their subdirectories Based on the option, that is, the search condition, starting from the given directory, so I think it is very good to say "Start directory" here.
The search condition in this command can be a composite condition consisting of not, And, or, a logical operator. Logical operators and, or, and not have the following meanings:
(1) and: logic and is represented by "-a" in the command. It is the default option of the system. It indicates that the search condition is met only when all the given items are met. For example:
Find-name 'tmp '-xtype C-user 'inin'
% This command looks for all files whose conditions are met
(2) or: logical or, represented by "-o" in the command. This operator indicates that the search condition is satisfied as long as one of the given conditions is satisfied. For example:
Find-name 'tmp '-o-name 'mina *'
% This command is used to query all objects whose names are 'tmp 'or match 'mina.
(3) Not: Non-logical. Use "!" in the command. . This operator is used to search for objects that do not meet the given conditions. For example:
Find! -Name 'tmp'
% This command is used to query all objects whose names are not 'tmp.
Note: When many logical options are used, you can enclose these options in parentheses. To avoid shell misunderstanding, you must add the Escape Character "\" before the phone number to remove the meaning of the brackets. Example:
Find \ (-name 'tmp '-xtype C-user 'inin '\)
I think now I should say that the following query conditions have been found:
In option, specific parameters are as follows:
-Name 'string': searches for all files whose names match the given strings. Wildcards *,? , [].
-Lname 'string': searches for all symbolic link files of the given string matching the file name. Wildcards *,? , [].
-Gid N: searches for all files belonging to the user group with ID n.
-Uid n: searches for all files belonging to users with ID n.
-Group 'string': searches for all files belonging to the string given by the user group name.
-User 'string': searches for all files belonging to the string given by the user name.
-Empty: searches for directories or files with a size of 0.
-Path 'string': searches for all files whose path names match the given strings. Wildcards *,? , [].
-Perm permission: searches for files and directories with the specified permission. The permission expression can be 711,644.
-Size N [bckw]: searches for objects of the specified file size. The character after N indicates the unit. The default value is B, which indicates the block size of 512 bytes.
-Type X: Search for objects of the X type. X is one of the following characters:
Block B Device Files
C character Device File
D directory file
P named pipe (FIFO)
F Common File
L Symbolic Links)
S socket File
-Xtype X and-type are basically the same, but only the symbolic link file is searched.
Search by Time
-Amin N: searches for all files that were accessed n minutes ago.
-Atime N: searches for all files that have been accessed n days ago.
-Cmin N: searches for all files whose status has been modified n minutes ago.
-Ctime N: searches for all files whose status has been modified N days ago.
-Mmin N: searches for all files whose contents have been modified n minutes ago.
-Mtime N: searches for all files whose contents have been modified N days ago.
-Print: outputs the search result to the standard output.
Example: in root and subdirectory search does not include directory/root/bin, Greek user, file type is normal file, 3 days ago named test-find.c file, and output the structure. The find command is as follows:
Find/-name "test-find.c"-type F-mtime + 3-user Greek-prune/root/bin-print
Of course,-print is a default option, so we do not have to configure it.
Let's take a look at the exec options:
-Exec: Specifies the shell command for the structure command to be searched. Note that the format must be correct: "-exec command {}\;"
There must be spaces between} And;
{} Indicates that the command parameter is the file found. The end of the command must end.
Example: run the following command to delete the files found in the preceding example:
Find/-name "test-find.c"-type F-mtime + 3-user Greek-prune/root/bin-exec RM {}\;
Find command instance:
Find.-Name 'main * '-exec more {}\;
% Search for all files starting with main in the current directory and display the contents of these files.
Find. \ (-name A. Out-o-name '*. o' \)-atime + 7-exec RM {}\;;
% Delete All A. out or *. O files not accessed in the current directory within one week. Note: there must be an interval between '\ (', '\)' and the following parameters.