The Centos find detailed

Source: Internet
Author: User


Function: Completes the file lookup by traversing the file system hierarchy under the specified starting path.

Working characteristics: Slow to find, exact search, fact finding;

How to use: Find [find starting path] [find condition] [processing action]

Find the starting path: Specify a specific search target starting path, default to the current directory;

Search criteria: The specified search criteria, can be based on the file name, size, type, engaged in relations, permissions and other criteria, the default is to find out the path of all the files;

Handling actions: Actions that are made on files that match the search criteria, such as deletions, which are output to standard output by default ;

Search criteria:

Expressions: Made up of options and tests

Search by file name:

-name "pattern"

-iname "pattern"

Supports GLOB-style wildcard printable in regular expressions *,?, [], [^]

-regex pattern: Finds a file based on a regular expression pattern, which matches the entire path, not its name;

Find based on file affiliation:

-user USERNAME: Find all files belonging to the owner of the specified user;

-group GRPNAME: Finds all files belonging to the specified group of groups;

-uid uid: Finds all files that belong to the UID specified by the master;

-gid GID: Finds all files belonging to the specified GID of the group;

-nouser: Find files that are not owned by the master;

-nogroup: Find files without a group;

Example: Find all files or directories in the/var directory that are subordinate to root and belong to the group mail;

Find/var-user root-a-group Mail-ls

Example: Find all files or directories that are not root, bin, or Hadoop under the/usr directory; in two ways;

Find/usr-not-user root-a-not-user bin-a-not-user Hadoop

Find/usr-not \ (-user root-o-user bin-o-user hadoop \)-ls

Find by File type:

-type Type:

F: Normal file

D: Catalog file

L: Symbolic Link file

B: Block device files

C: Character device file

P: Pipeline File

S: Socket file

Example: Find path-type file type

Combination test:

With:-A, the default combination logic; (also satisfies the relevant conditions)

Or:-O (satisfies one of the conditions)

Non:-not,! (Take the reverse)

Example: Find path condition 1-a Condition 2 (Find condition 1 and Condition 2 must be met)

Find by file size:

-size [+|-] #UNIT

Common units: K, M, G

#UNIT: (#-1, #] equals #

-#UNIT: [0,#-1] less than #

+ #UNIT: (#, OO) greater than #

Example: Find path-size #k (find files with file size #k)

Example: Look for all files with a type of normal file that is larger than 1M in the/etc directory;

Find/etc-size +1m-type f-exec ls-lh {} \;

Find by Time stamp:

In "Days" as the unit:

-atime [+|-]# Last Access time

#:[#, #-1)

-#: (#, 0]

+#: (Oo, #-1)

-mtime Last Modified Time

-ctime Recent Change Time

In "Minutes" units:




Example: find in/etc directory in the last week of its content has been modified, and the owner is not the root user is not a Hadoop user files or directories;

find/etc-mtime-7-a-not-user root-a-not-user hadoop-ls

Example: Find files or directories that are not owned or belong to a group on the current system and have been visited in the last week;

Find/\ (-nouser-o-nogroup \)-atime-7-ls

Search by permissions:

-perm [/|-]mode

Mode: precise permission matching;

/mode: Any one (r,w,x) of the permissions of any class of users (U,g,o) is satisfied with the condition;

There is a "or" relationship between 9-bit permissions;

-mode: Each class of users (U,g,o) in the permissions of each bit (r,w,x) at the same time meet the condition is satisfied;

There is a "and" relationship between 9-bit permissions;

Example: Find files in/etc directory where all users do not have write permission;

Find/etc-not-perm/222-type F-ls

Example: To find at least one class of users who do not have permission to execute files;

Find/etc-not-perm-111-type F-ls

Example: Find/etc/init.d/directory, all users have execute permission, and other users have write permission to all files;

Find/etc-perm-113-type F-ls

Handling actions:

-print: Output to standard output, default action;

-ls: Similar to the "ls-l" command for the found file, the output file details;

-delete: Delete the found file;

-fls/path/to/somefile: Saves the long format information of all files found to the specified file;

-ok COMMAND {} \; : Executes commands for each file that is found, and each operation is confirmed by the user;

-exec COMMAND {} \; : Executes commands for each file that is found;

Note: Find passes the file path found to the following command, it is first to find out all eligible file paths, and one-time pass to the following command;

However, some commands cannot accept too long arguments, at which point the command execution fails, and another way to circumvent this problem: find | Xargs Comman

Security context

1, the process to run the identity of users; A process is the agent that initiates the user of this process, and therefore completes all operations with the identity and permissions of the user;

2. Permission Matching model:

Determines whether the owner of the process is the owner of the file being accessed, or if the owner's permission is applied, otherwise the Access file is not specifically defined to the user's access control list, if any, then the second step;

The owner of the second judgment process, whether it belongs to the file belonging to the group; if it is, the permissions of the group are applied, otherwise the access control list is not specifically defined to the user; otherwise, the third step is entered;

Third, the permission to apply other;

The Centos find detailed

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.