Shell command - Search the file or directory of whereis, locate

Document and content processing - whereis, locate

1. whereis: Find a binary command, press the PATH environment variable to find the path

Whereis command function description

whereisCommand is used to locate the file. This instruction will find qualified files in a specific directory. These documents should belong to the original code, binary files, or help file. This command can only be used to find binary files, source code files and manmanual pages, locate the file in general need to use locatethe command.

Whereis command syntax

whereis[Options] [-BMS Directory ... -f] name ...
whereis[-bfmsu] [- B <directory> ...] [- M <directory> ...] [- S <directory> ... ][file...]

whereis common parameters command Description:

whereisSmall parameters in Table 1 for the whereisparameters and descriptions of commands:

Table 1: whereis Parameters and descriptions of commands

Parameter options explain
-b  Find only binary files.
-B <directory>  Find only binary files in the directory settings.
-f  Does not display the name of the path before the file name.
-m  Finding just the documentation.
-M <catalog>  Only to find documentation in the directory settings.
-s  Only to find the original code files.
-S <catalog>  Only to find the original code files in the directory settings.
-u  Find does not contain the specified type of file.

Whereis command of practical operation

Example 1: using the instruction whereisto view the command cpposition, the following command input

[root@m01 ~]# whereis cp
cp: /usr/bin/cp /usr/share/man/man1/cp.1.gz

Note: The above information is output from left to right as the program name query cppath, cpthe manman page path

Example 2: separate inquiry binary file or help file, use the command

[root@m01 ~]# whereis -b cp
cp: /usr/bin/cp
[root@m01 ~]# whereis -m cp
cp: /usr/share/man/man1/cp.1.gz

2. locate: Find command from the label database (/var/lib/mlocate/mlocate.db), update the library using updatedb

Function locate command Description

locateCommand is used to find qualified document, he will go to save a database file and directory names, find the document or template style directory in line with the conditions. Normally we only need to enter locate your_file_nameto find the specified file. CentOS 7 This command has no need to manually install, method:

yum install -y mlocate

Locate command syntax

locate[--version]
locate[-d] [- Help] [- Version] [template styles ...]

Description of common parameters locate command:

locateSmall parameters in Table 1 for the locateparameters and descriptions of commands:

Table 1: locate Parameters and descriptions of commands

Parameter options explain
-d or --database = Locate configuration database used by the instruction. locate command default database located in / var / lib / slocate directory, document named slocate.db, you can use this parameter specify otherwise.
--help Online help.
--version Displays version information.

Hands-locate command

Example 1: Find passwdthe file, enter the following command

locate passwd

Additional information
locateand finddifferent: findare hard to find, locateonly /var/lib/slocateto find the library.
locateFaster than findfast, it does not really look, but check the database, the database file in general /var/lib/slocate/slocate.db, the so locatelookup is not real-time, but subject to update the database, usually maintain their own system, you can also manually upgrade database, the command is

locate -u 

Today I write to you, have any questions or something goes wrong, feel free to enlighten the great God who comment

Guess you like

Origin blog.51cto.com/14068656/2408171