Five search commands in linux and five search commands in linux

Source: Internet
Author: User

Five search commands in linux and five search commands in linux
1 which

The which command searches for the location of a system command in the PATH specified by the PATH variable and returns the first search result.

   

Which [file...]

Parameters:

-N <file name length> specifies the file name length. The specified length must be greater than or equal to the longest file name in all files.

-P <file name length> is the same as the-n parameter, but the <file name length> here includes the file path.

-W specifies the width of the field when the output is made.

-V: display version information

Strange: why can't we find the cd commands we often use? This is because cd is a bash built-in command, and which defaults to find the standard directory in PATH, so it cannot be found. We can use the type command to see

 

2 type

The type command is actually not a search command. It is used to identify whether a command is provided by shell or an independent binary file outside the shell. If a command is an external command, use the-p parameter to display the path of the command, which is equivalent to the which command.

 

3 whereis

The whereis command is used to find the command location,Includes execution files, source code files, and manual page files. If you want to find the location of any file, you can use the locate or find command. The usage instructions are as follows:

   

Whereis [-bfmsu] [-B...] [-M...] [-S...] [file...]

-B only searches for binary files.
-B only searches for binary files in the Set directory.
-F does not display the path name before the file name.
-M: only find the description file.
-M only searches for instruction files in the specified directory.
-S only searches for original code files.
-S only searches for the original code file in the Set directory.
-U: Find Files that do not contain the specified type

4 find

Find is the most powerful file search command. The command usage is as follows:

   

Find [PATH] [option] [action]

Common parameter search methods
Time search parameters:
-Atime n: lists the files that have been retrieved from the memory for n * 24 hours.
-Ctime n: lists the files or directories that have been changed or added within n x 24 hours.
-Mtime n: lists the files or directories modified within n x 24 hours.
-Newer file: Lists files that are newer than file.


Name Search parameters:
-Gid n: Find the file whose group ID is n.
-Group name: Find the file with the group name
-Uid n: Find the file whose owner ID is n.
-User name: Find the file whose user name is name
-Name file: searches for files with file names (wildcards can be used)

The Time Parameter in find is very interesting. For more information, see

Find command is very strong, more detailed use of reference man find or laruence private house dish this book http://vbird.dic.ksu.edu.tw/linux_basic/0220filemanager_5.php#find

5 locate

The locate command is actually another method of writing "find-name", but it is much faster than the latter because it does not search for a specific directory, instead, search for a database (/var/lib/locatedb) that contains information about all local files. The Linux system automatically creates the database and updates the database once a day. Therefore, the latest changed files cannot be found using the locate command. To avoid this problem, you can useUpdatedbCommand to manually update the database.

   

Use instance of the locate command:

$ Locate/etc/sh

Search for all files starting with sh in the etc directory.

$ Locate ~ /M

Search all files starting with m in the user's home directory.

$ Locate-I ~ /M

Search all files starting with m in the user's home directory, and ignore the case.

6 References
Linux File SEARCH Command comparison

Yes.
Locate: This is not available in some linux systems. Before running, you need to update the database by using updatedb, especially when there are newly generated files for the first time.
Grep command: If you know the directory in which the file is located, you can use ls | grep file name.
Which: view the storage address of the system command, such as: which ls
Whereis
And so on .........

Search for files in linux

Find. You can search for all files that meet the conditions without specifying the path.
Find-name 'your filename'

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.