Linux next 4 Find commands summary of which, Whereis, locate, find

Source: Internet
Author: User

(1) which [-a] cmdname1 cmdname2 ...

Role: Locate a command, from the environment variable path, locates/returns the path to the executable file that matches the specified name

Principle: When executing the which command, which will look in the current environment variable path for the executable file name that matches the name of the given command, without the-a option, and return the path to the first matching executable, or return the path name of all executables that meet the criteria, in turn.

Application: Typically used to find the path where the command/executable is located. Sometimes the same command may exist under multiple paths, which can be used to find the command at which point the currently executing command is located.

(2) Whereis [-BMSU] filename1 filename2 ....

Functions: Locate the binary, source, and manual page files for a command. That is: Locate/return the path to the binary file, source file, and help book file that match the specified name.

Principle: The Whereis command first removes the prefix spaces in filename and any characters that begin with., and then finds binary files in the database (VAR/LIB/SLOCATE/SLOCATE.DB) that match the previously processed filename, source files and help book files, you can manually update the database using the UpdateDB command before using it.

Application: Search for binary files, source files, and help book file paths.

(3) Locate [option] filename1 filename2 ...

Function: Find files by name from one or more databases prepared by UpdateDB. As with the Whereis directive, it is also found from the database-built index, where the command looks for all partially matched files and can be manually updated with the UpdateDB command before using the.

Principle: By default (when filename does not contain a wildcard character *), locate gives the path to all files that match *filename*.

Application: No Fuzzy Lookup of file type nature (you only remember part of a file name).

(4) Find [option] [path1 path2 ...] [FileName]

Parameter description:

Time Lookup Parameters:

-atime N: List files that have been accessed in n*24 hours

-ctime N: List the files that have changed status within n*24 hours

-mtime N: Lists files that have been modified in n*24 hours

-newer file: List files that are newer than

Name Lookup parameters:

-gid N: Looking for a file with group ID n

-group Name: Find a file with the name of the group

-uid N: Looking for a file with owner ID n

-user Name: Find the file with the owner name called name

-name file: Look for files named file (wildcard characters can be used)

Role: Search for files in a directory hierarchy. Searches for files recursively from the current directory.

Principle: Traverse the current working directory and its subdirectories, the Find command is to traverse lookups on the hard disk, consuming hard disk resources, and finding efficiency is lower than whereis and locate.

Application occasions: can use which, whereis and locate when try not to use find.

A comparison of 4 commands is shown in the following table:

Linux next 4 Find commands summary of which, Whereis, locate, find

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.