Linux's five lookup commands

  

In Linux, there are many ways to do this. The foreign website LinuxHaxor summarizes five commands, you can see if you know a few. Most programmers may use two or three of them, and there are not many people who are familiar with these five commands.

1. find

find is the most common and powerful search command you can use to find any file you are looking for.

The format of find is as follows: $ find <specified directory> <specified condition> <specified action> - <specified directory>: directory to be searched and all its subdirectories. The default is the current directory. - <specified condition>: The characteristics of the file to be searched. - <Specify action>: Perform specific processing on the search result.

If nothing is added, find defaults to the current directory and its subdirectories, and does not filter any results (that is, returns all files), displaying them all on the screen.

Example of use of find: $ find . -name 'my*' searches for the current directory (including subdirectories, the same below), all files whose names begin with my. $ find . -name 'my*' -ls Searches for files in the current directory with all file names starting with my and displays their details. $ find . -type f -mmin -10 Searches all the normal files that have been updated in the past 10 minutes in the current directory. If the -type f parameter is not added, the normal file + special file + directory is searched.

2. locate

The locate command is actually another way of writing “find -name” but it is much faster than the latter because it does not search for specific directories, but instead Search for a database (/var/lib/locatedb) that contains all local file information. The Linux system automatically creates this database and automatically updates it once a day, so you can't find the latest changed files using the locate command. To avoid this, you can manually update the database using the updatedb command before using locate.

Use examples of the locate command: $ locate /etc/sh Search all files in the etc directory that start with sh. $ locate ~/m searches for all files starting with m in the user's home directory. $ locate -i ~/m Searches all files starting with m in the user's home directory, and ignores case.

3. whereis

whereis command can only be used for program name search, and only search binary files (parameter -b), man description file (parameter -m) and source code file ( Parameter -s). If the parameter is omitted, all information is returned.

The use of the whereis command: $ whereis grep

4. which

the purpose of the command is to search for a system command in the path specified by the PATH variable. Location and return the first search result. In other words, using the which command, you can see if a system command exists and which command is executed.

The use of the which command: $ which grep

5. type

type command can not be counted as a find command, it is used to distinguish a command from the shell It comes with it, or it is provided by a separate binary file outside the shell. If a command is an external command, then using the -p parameter will display the path to the command, which is equivalent to the which command.

Example of the use of the type command: $ type cd system will prompt, cd is the shell's own command (build-in). The $type grep system prompts that grep is an external command and shows the path to the command. $ type -p grep plus the -p parameter is equivalent to the which command.

Copyright © Windows knowledge All Rights Reserved