Linux Lookup File Command __linux

Source: Internet
Author: User

Linux has the following 4 main commands related to lookup: Whereis, locate, find, which. Find is not commonly used, whereis and locate often used, because Whereis and locate is to use the database to find data, and found directly look for hard disk, slower. Which searches for the location of the specified system command in the path specified by the PATH variable. Let's talk about their usage

Whereis

The Whereis command can only search for user program names, that is, locate/return the path to the binaries, source files, and help book files that match the specified name.

Whereis Lookup is very fast because the Linux system will record all the files in the system in a database file, when using Whereis and locate, will look up the data from the database, rather than the Find command, by traversing the hard disk to look up, the efficiency will be very high. But the database file is not a live update and is updated once a week by default, so when we use Whereis and locate to find the file, we sometimes find the data that has been deleted, or we just set up the file, but we can't find it because the database file is not updated.

Whereis [-BMSU] file or directory name

-B: Only files in binary format are found

-M: Only files found in the manual of the explanatory file

-S: source source files only

-U: Find other special files that are not in the above three options

For example:

Root@test config]# Whereis Find
:/bin/find/usr/bin/find/usr/share/man/man1/find.1.gz

[root@test config ]# whereis-b Find
:/bin/find/usr/bin/find

[root@test config]# whereis-m find
:/usr/share/man/ man1/find.1.gz

[root@test config]# whereis-s Find
:

[root@test config]#-Whereis-u find
:/bin /find/usr/bin/find/usr/share/man/man1/find.1.gz

Locate

The use of more than Whereis, only a partial file name can be fuzzy query, while LOCTE can also use the-r option using regular expressions, powerful. As with Whereis, the information in the indexed database used by locate is not necessarily real-time, and you can update the index database using the UpdateDB command

Locate [-ir] keyword

For example: Query passwd command, find files containing passwd characters, display the first 3 records

[Root@oracledb ahome]# Locate passwd|head-n 5
/etc/passwd
/etc/passwd-

Find
The command traverses the current working directory and its subdirectories, traversing the search on the hard disk, consuming hard disk resources and using which, whereis and locate.

Find [option] [path1 path2 ...] [FileName]
Parameter description:
Time Lookup Parameters:
-atime N: Lists files for access in n*24 hours
-ctime N: Lists files that have changed status within n*24 hours
-mtime N: Lists files that have been modified in n*24 hours
-newer file: Make a list of files that are newer than file
Name Lookup parameters:
-gid N: Searching for files with group ID n
-group Name: Search for files with group names of name
-uid N: Looking for files with owner ID n
-user Name: Find a file with the owner name called name
-name file: Looking for files with file name files (wildcard characters can be used)

which

When you execute the which command, which in the current environment variable path to find the executable file name that matches the name of the command you are looking for, without the-a option, return the path of the first matching executable file, or else return the pathname of all executables that meet the criteria in turn.

Typically used to find the path where the command/executable file resides. It is sometimes possible to have the same command under multiple paths, which can be used to find the command at which the currently executing command is located.

The following is a comparison

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.