Linux Learning Diary--Basic Command (10)--File search

Source: Internet
Author: User

File Lookup:

File Lookup: Locate, find
Non-real-time lookup (Database lookup): Locate
Real-time Find: Find

Locate

Dependent on pre-built indexes; The index is built automatically when the system is idle (periodic tasks); Manually update the database (UPDATEDB);

The index construction process needs to traverse the whole root file system, consuming resources extremely;

Working characteristics:
Fast search speed;
Fuzzy search;
Non-real-time lookup;

Locate KEYWORD


Find:
Real-time Find tool to complete file search by traversing the file system under the specified path;

Working characteristics:
The search speed is slightly slower;
Accurate search;
Real-time search;

Grammar:
Find [OPTION] ... [Find Path] [Search Criteria] [Handling Action]
Find path: Specify the target path, default to the current directory;
Search criteria: The specified search criteria can be file name, size, type, permissions and other standards, the default is to find all the files under the specified path;
Handling actions: What to do with the eligible files; default output to the screen;

Search criteria:
Search by file name:

-name "file name": Support for using Glob
*, ?, [], [^]
-iname "file name": Letter case insensitive

-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 belonging to the owner of the specified user;
Group GRPNAME: Find files that belong to a specified group;

-uid UserID: Find the file that belongs to the UID number specified by the owner;
-gid GroupID: Finds files belonging to the specified GID number;

-nouser: Find files that are not owned by the master;
-nogroup: Find files without a group;

Find by file type:
-type Type:
F: Normal file
D: Catalog file
L: Symbolic Link file
S: Socket file
B: Block device files
C: Character device file
P: Pipeline File

Combination conditions:
With:-A
Or:-O
Non:-not,!

! A-a! B =! (A-o B)
! A-o! B =! (A-a B)

depending on the file size, look for:
-size [+|-] #UNIT
Common units: K, M, G

#UNIT: (#-1, #)
-#UNIT: [0,#-1]
+ #UNIT: (#,oo)

based on time stamp:
Take "Day" as the unit;
-atime [+|-]#,
#: [#,#+1]
+#: [#+1,oo]
-#: [0,#]
-mtime
-ctime

In "Minutes" units:

-amin
-mmin
-cmin

Search by permissions:

-perm [/|-]mode
MODE: Exact permission match
/mode: The permission of any class (U,g,o) object can only be matched by one match;
-mode: Each type of object must have a permission standard assigned to it at the same time;


Handling actions:
-print: The default processing action, display to the screen;
-ls: Similar to executing the "ls-l" command on the found file;
-delete: Delete the found file;
-fls/path/to/somefile: Long format information for all files found is saved to the specified file;
-ok COMMAND {} \; Executes commands specified by the command for each file found;
User confirmation is requested interactively before each file executes the command;
-exec COMMAND {} \; Executes commands specified by the command for each file found;
{}: Used to refer to the file name itself;

Note: When find passes the found file to the command specified later, it finds all eligible files once passed to the following command;
Some commands cannot accept too many arguments, at which point the command execution may fail, and another way to circumvent this problem:
Find | Xargs COMMAND


Linux Learning Diary--Basic Command (10)--File search

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.