Linux system Find command use Daquan __linux

Source: Internet
Author: User
usage: Find [h] [l] [-p][-olevel] [D-help|tree|search|stat|rates|opt|exec] [path ...] [Expression]

Find [Start directory] look for conditional actions

There is a way of saying: Find PATH OPTION [-execcommand {} \;]

The Find command will be based on option, which is to search for the conditions from the given directory to start on the file in which the file and its subdirectories are recursively searched,

The search condition in this command can be a compound condition that is composed of not, and, or the logical operator. The meaning of the logical operator and, or, not is:

(1) and: logic and, expressed as "a" in the command, is the default option for the system, indicating that the condition is satisfied only if the given condition is satisfied. For example:

Find–name ' tmp ' –xtype c-user ' inin '

#该命令寻找三个给定条件都满足的所有文件

(2) or: logic or, in the command, "-O". This operator indicates that a condition is satisfied if one is satisfied in the given condition. For example:

Find–name ' tmp ' –o–name ' mina* '

#该命令查询文件名为 ' tmp ' or all files that match ' mina* '.

(3) Not: illogical, in command "!" Said. This operator represents the lookup of a file that does not meet the given criteria. For example:

Find! –name ' tmp '

#该命令查询文件名不是 all files for ' tmp '.

It should be explained that when you use a lot of logical options, you can enclose these options in parentheses. To avoid misinterpretation of parentheses by the shell itself, it is necessary to add the escape character "\" before the word number to remove the meaning of the parentheses. Cases:

Find \ (–name ' tmp ' –xtype c-user ' inin ')

Query criteria:

In option, the specific parameters are:

-name ' string ' finds the file name matches all the files for the given string, and the wildcard character * 、?、 [] is available within the string.

-lname ' string ' finds the filename matches all the symbolic link files for the given string, and the wildcard character * 、?、 [] is available within the string.

-gid N finds all files that belong to a user group with an ID number of n.

-uid N finds all files belonging to the user with ID number n.

-group ' string ' looks for all files that belong to the given string named by the user group.

-user ' string ' finds all files that belong to a given string of user names.

-empty find directories or files of size 0.

-path ' string ' finds all files that match the given string, and the wildcard character * 、?、 [] is available within the string.

-perm permissions to find files and directories with the specified permissions, the representation of the permission can be as 711,644.

-size n[bckw] looks for files of the specified file size, and the characters after n indicate units, the default is B, which represents a 512-byte block.

-type x finds a file of type X, and X is one of the following characters:

B Block Device file

C Character device file

D Catalog Files

P Named pipe (FIFO)

F Normal File

L Symbolic Link file (Symbolic links)

s socket file

-xtype x is basically the same as-type, but finds only symbolic link files.

Find time as a condition

-amin N finds all files that have been accessed before n minutes.

-atime N finds all files that have been accessed before n days.

-cmin N finds all files where the file state was modified before n minutes.

-ctime N finds all files where the file state was modified before n days.

-mmin N finds all files where the contents of the file were modified before n minutes.

-mtime N finds all files where the contents of the file were modified before n days.

-print: Outputs the search results to standard output.

Example: in root and subdirectory lookup does not include directory/root/bin, Greek user, file type is normal file, 3 days before the file named TEST-FIND.C, and the structure output, find command as follows:

Find/-name "TEST-FIND.C"-type f-mtime +3-user Greek-prune/root/bin-print

Of course in this,-print is a default option, and we don't have to configure it deliberately.

Let's take another look at the EXEC option:

-exec: Shell command specified for the structure instruction of the search. Note The format should be correct: "-exec command {} \;"

between} and \ must have a space to do;

{} indicates that the command's argument is the found file; the end of the command must be "\;" End.

Example: The search for the above example of the file to delete operations, the command is as follows:

Find/-name "TEST-FIND.C"-type f-mtime +3-user greek-prune/root/bin-exec rm {} \;

Find command Instruction instance:

Find. -Name ' main* '-exec more {} \;

#查找当前目录中所有以main开头的文件, and displays the contents of these files.

Find. \ (-Name A.out-o-name ' *.O ' \) >-atime+7-exec rm {} \;

#删除当前目录下所有一周之内没有被访问过的a. Out or *.O files.

#命令中的 "." Represents the current directory, at which point

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.