Shell command Find

Source: Internet
Author: User

Introduced

Find命令的工作方式:沿着文件层次结构向下遍历,匹配符合条件的文件,并执行相应的操作。

Options

-print: Indicates the file name (path) to print out the matching file. When using-print, ' \ n ' as the delimiter used to separate files

-print0: Indicates that each matching file name is printed using '% ' as a delimiter. This method is useful when the file name contains a line break.

-name: Specifies the string to which the file name must match. Wildcard characters supported

Find/home/dd-name "*.txt"-print

-iname:-name ignoring case

-path: Match path, wildcard character is supported.

Find. -path "*www*"

-perm: Specify Permissions

-regex: Using regular expressions to match files

Find. -regex ". *\ (\.py\|\.sh\) $"

-iregex:-regex ignoring case

-maxdepth: Specifies the maximum depth directory to find

Find. -maxdepth 1-type F-print

-mindepth: Specifies the first depth of the directory to start looking for

Operator

(expr): Force precedence.

Expr1 EXPR2

Expressions in a row is taken to being joined with an implied "and"; EXPR2 is isn't evaluated if EXPR1 is false.
Find. -name ' 1.txt '-type f-user ' PDD '

! Expr: Logical Non-

Find it! -name ' tmp '

Expr1-a EXPR2: Logical AND, default options

Same as Expr1 expr2.

Expr1-o EXPR2: Logical OR

or; EXPR2 is isn't evaluated if EXPR1 is true.

Find. \ (-name "*.txt"-o "*.pdf" \)-print

-type: Specifies the type of file to find

B-Block Equipment

C-Character device

Catalog D

F Common Files

L Symbolic Link

P FIFO

s socket

Search by file time (-{a,m,c}time measured in days,-{a,m,c}min in minutes)

Access Time (-atime,-amin): The last time a user accessed a file

Modification Time (-mtime,-mtime): The time the file content was last modified

Change Time (-ctime,-cmin): File metadata (metadata, such as permissions or ownership) time of last change

Find. -type f-atime-7-print # files visited in the last seven days

Find. -type f-atime 7-print # files visited exactly seven days ago

Find. -type F-atime +7-print # files with access times longer than seven days

-size: Search According to the size of the file

B Block (512 bytes default)

C bytes

W Word (2 bytes)

K Kbytes

M MBytes

G gigabyte

Find. -type f-size +2k # files larger than 2KB

Find. -type f-size-2k # files less than 2KB

Find. -type f-size 2k # equals 2KB file

-delete: Delete a found matching file

-user (can be a user name or UID): Find files owned by a specific user

-exec command {} \;: Combined with other commands

Find. -type f-user root-exec chown www {} \;

In this command, {} is a special string that is used in conjunction with the-EXEC option. For each matching file, {} is replaced with the corresponding file name. For example, the above command finds two files Test1.txt and Test2.txt, which will eventually be parsed bit chown www test1.txt and chown www test2.txt

-prune: Skips the specified directory

Find. -path./pdd-prune-o-print

Shell command Find

Related Article

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.