Linux: Search for commands and archives

Source: Internet
Author: User

V Search method under Linux (reference from Bird's-brother Linux Private Cuisine Basics):

First,find : The function is very powerful, directly search the entire hard disk (speed is not fast, if the system hard disk is older)----features: Find can be followed by multiple directory search, which itself will search the secondary directory

  Main syntax: find [path] [option] [action]

Category (1): The main three-time file search method (mtime "File content modification Time", atime "file fetch time CAT,HEAD,NL, etc.", ctime "file status time, permissions, Attributes", newer (find files newer than a file))

Syntax: find [path] [-mtime|-ctime|atime] [|+|-] n (number)

Find [path] [-newer] [File (to find files that are newer than the profile)]

  

  

  Category (2): Parameter lookup method (user ID, group ID (ID username), user name, group name, Nouser (person not in/etc/passwd), Nogroup (group not in/etc/group), associated with the consumer or group

Syntax: find [path] [-uid|-gid|-user|-group] [Uid|gid|username|group (via "id Zengguowang" get Uid,gid)]

Find [path] [-nouser|-nogroup (Find files for users not in/etc/passwd, files not in/etc/group Group)]

  

  Category (3): Parameter lookup method related to file permissions and names

  syntax: Find [path] [-name|-size|-type] [Filename| (+|-) (c:bytes|k:1024bytes) |f, B, C, L, D, S, p]

Find [path] [-perm] [4755|-4755|/4755]

  

  Category (4): Find finds additional operations that can be performed (such as querying to an ASCII text-only document, querying it with cat-n display content)

Syntax: find [path] [-mtime|-uid|-name] [parameter] [-exec] [ls-l (extra instruction Cat-n)] [{} \;]

For example: Find/-perm/7000-exec ls-l {} \;

    

  Attention:

To find the file with special attributes, such as suid, owner, file size, using locate is not up to the search

find can also use the " Universal Characters "*" "

    "!" is not equal to (reverse selection) meaning ; For example: Find file size greater than 50k not root files Find/-size +50k! -user root (Find/!-user root)

    "-A" is the meaning of and, for example, find files larger than 50k less than 60k find/-size +50k-a-szie-60k

    "-O" is the meaning of OR. For example, I want to find files greater than 1500k and capacity equal to 0 find/-size +1500k-o-size 0

Second,which (command search): is based on [path] This environment variable planning path to search the file name of the execution file (cannot find history because it is a bash shell built-in instructions, using type history can be searched)

  

Archive search:

  Note: Usually find is not very common, because it is slow, and very hard, usually first use Whereis and locate to check, if you can not find and then use Find, why?

A: Because Whereis only find files in certain directories in the system, locate is the repository to find the file name, both of which are quite fast, and do not actually search for the file system status in the hard disk, it is relatively time-saving

Third,Whereis(Locate): Query the system for some specific directories

  

Iv.Locate archive search (updatedb) database/var/lib/mlocate/: Querying the System preset database (CENTOS7. X's database preset is updated every day, when you create a new file in the database is not updated before the query, will be prompted to find, you must wait for the database to update before the line "use the UpdateDB command to update the database, UpdateDB will go to read/etc/ updatedb.conf settings, and then go to the hard drive to find the name of the action, and then update the entire database file, because updatedb back to search the hard disk, so very slow, when executed, to wait a few minutes ")

  

  UpdateDB: According to the/etc/updatedb.conf set to search the system's hard disk name, and update the/var/lib/mlocate in the archives;

Locate: According to the information in the/var/lib/mlocate, find out the user input key file name.

type : used to differentiate whether the shell comes with or is provided independently by a binary file other than the shell; If a command is an external command, then using the-P (p) parameter will display the path to the command, equivalent to the which command

Example: Type history (shell comes with)

Type-p ls (a command independently provided by a binary file outside the shell)

  

  

Linux: Search for commands and archives

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.