Linux Find using Tutorials

Source: Internet
Author: User
Tags glob

Find Basics


File Lookup: The process of locating a qualifying file on a file system;


File Lookup command: Locate, find

Locate: A non-real-time lookup tool that relies on a pre-built index, which is built automatically when the system is idle (periodic tasks), manually updating this database (updatedb), searching fast, and fuzzy lookups;

Find: real-time search; search speed slightly slow; exact search;


Find command:

Find [OPTION] ... [Find Path] [Search Criteria] [Handling Action]

Find path: Default to the current path;

Search criteria: The specified search criteria, can be based on the file name, size, genus of the main group, type, etc., by default to find all the files under the specified path;

Handling actions: What to do with the eligible files; By default, output to the screen;


Search criteria:

To find by file name:

-name "file name": Supports the use of glob (*,?, []);

-iname "file name": Character case insensitive, support for using Glob

-regex "pattern": matches the entire file path string with pattern, not just the file name


According to the genus, the genus Group looks for:

-user USERNAME: Find files that belong to the specified user

-group GROUPNAME:

-uid UserID: A file that finds the owner-specified UID of a file;

-gid GroupID:

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

-nogroup: Find files without a group;


To find by file type:

-type type

Type types are:

F: Normal file

D: Catalogue

L: Symbolic Link

B: Block device

C: Character device

P: Named Pipes

S: Socket


Combination Lookup criteria:

and Conditions:-A

or condition:-O

Non-conditional:-not,!

Depending on the file size, look for:

-size [+|-]num

Unit: K, M, G

+num: (Num,+oo] The value of the lookup if set to X (same as), the range is: X>=num

Num: (NUM-1, num] range is: num-1<=x<num

-NUM:[0,NUM-1] Range is: 0<x<num-1


Based on time stamp:

In "Days" as the unit

-atime (last accessed time)

+num:[num+1, +00] Range: x>num+1

num:[num,num+1) Range of num<x<=num+1

-num:[0,num) Range of 0<x<=num


Note: This must be distinguished from the-size value range, which is easily confused.


-mtime (last file modification time)

-ctime (last File property modification time)



Based on permissions:

-perm [/|-]mode

MODE: Exact permission match

/mode: Any one of a class of objects (U,g,o) is eligible for any of the rights, implied or conditional;

-mode: Every permission specified for each class of object must be in accordance with the condition;


Handling actions:

-print: Default handling action

-ls: Similar to the "ls-l" operation for each file found;

-delete: Delete the found file;

-fls/path/to/somefile: The detailed path information of the found file is saved to the specified file;

-ok COMMAND {} \;

The user must be confirmed beforehand before executing the specified command for each file;

-exec COMMAND {} \;

No user confirmation required;


Actual combat

1, find the/var directory is the owner of the root, and belong to the group mail all files;

Answer: find/var-user root-a-group Mail


2. Find all files that are not root, bin or hadoop under the/usr directory;

Answer: find/usr-not \ (-user root-o-user bin-o-user hadoop \)


3. Find all files whose contents have been modified and are not root or Hadoop for the last week in/etc directory;

Answer: find/etc-mtime-7-a-not \ (-user root-o-user hadoop \)


4. Find all files on the current system that are not owned by the master or group, and have been visited in the last week;

Answer: Find/\ (-nouser-o-nogroup \)-a-atime-7


5. Find all files in/etc directory greater than 20k and type ordinary files;

Answer: find/etc-size +20k-a-type F


6, look for all the users in/etc directory do not have permission to write files;

Answer: find/etc-not-perm/222


7. Find at least one class of users who do not have permission to execute files in/etc directory;

Answer: find/etc-not-perm-111


8, find/etc/init.d directory, all users have execute permission, and other users have write permission files;

Answer:find/etc/init.d-perm-111-a-perm-002




This article is from the "Wind Rhyme" blog, please be sure to keep this source http://chinalx1.blog.51cto.com/2334265/1691658

Linux Find using Tutorials

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.