linux--File Lookup

Source: Internet
Author: User
Tags egrep

2017-08-11 19:12:55 @ but may this heart have no grudge

A simple summary of common search methods for files in Linux today

In short, the use of the locate and find commands

Locate Query File Introduction

Syntax locate [options] keyword

Command options

- i case-insensitive search

-N enumeration of the top n items

-R Support regular

This command is not real-time query, but query the system above the pre-built file index library file /var/lib/mlocate/mlocate.db

UpdateDB Command Update locate database or exit and re-enter

The test is as follows:

query all files ending with. conf (because the result is too long, only the part is truncated), and then /app the directory to create the file test, query /app/test, after updating the locate database, query again.

Easier to use, faster to find

Find File Description

syntax Format find [ Find path ](default current)[ find Condition ] [ processing Action ](default is output to terminal)

Features real-time query, slow, but more complete function

[ search Criteria ] (Common)

-maxdepth level Specifies the maximum search depth

-minxdepth level Minimum search depth

-name exact name-based lookups

-iname Exact Lookup lookup based on name ignoring case

-regex Support Regular default to (emacs Standard)

-regextype Egrep-regex supports egrep with standard regular

-user user name based on file owner Lookup

-group group name based on The search of file group

-perm search based on permissions

-nouser to find files without owner

-nogroup finding files with no group

-type file Type-based lookups

? F: Normal file

? D: Catalog Files

? L: Symbolic Link File

? s : Socket file

? B: Block device Files

? C: Character device Files

? P: Pipeline Files

-size [+|-] #UNIT find eg-size based on file size 5M

Common units:K, M, G,C(byte)

+6m indicates a lookup range of (6M,∞]

-6m indicates a lookup range of [0,5m]

6M indicates a lookup range of (5m,6m]

-atime,-mtime,-ctime(in days)

-amin,-mmin,-cmin(in minutes)

the use is similar to-size

For example

-atime-3 = [0,3]

-atime +3 = {4,∞)

-atime 3 = [3,4]

Support -a(default)-o-not(or ! ) ) Check the conditions of the review

Some of the options are tested below

Find files with a maximum depth of 3 under the/app directory

Find files with the name A.1 in the current directory; Find files of the current directory type as normal files

use-regextype grep to specify the type of grep that can be used

for -perm based on permissions to find the description and test the following

-perm 444 represents a file that queries a specified permission of 444

-perm/444 means finding a file (or relationship) with 4 in the Ugo

-perm/044 means to find Any one of the 4 files in Go,0 means no consideration for this bit permission

-perm-044 for files (and relationships) that look for G and o are 4 permissions

TestThe following,/app create files test1,test2, and change their permissions to test as follows

[ processing Action ] ( common )

-ls The query file information length list

-delete Delete a queried file

-fls filename Lists the length of the queried file and stores it in filename

-ok comman \; the query file is Command operation, inquiry way to carry out each time Command Operation

-exec and -ok , but not the command operation of each file in the form of a query

Ps:{} represents a file referencing a query

For example: Create a file test1-10below/app, find and delete files test1-9

Summing up, for the method of finding files locate fast, but not real-time query, function is relatively single, find function is more complete, real-time query can be combined with other commands to achieve more operations, but the search speed is slow.

linux--File Lookup

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.