Which and Whichis file directory lookup function in Linux

Source: Internet
Author: User


Whereis find specific files for system commands

1. Command format

WHEREIS-BMSU search string-b:binary only binary files
-m:manual Search for manuals-related files only
-s:source only search the original code files
-u:unusual A special file, this parameter is rather strange
2. Command test

Search for files related to AddUser command

$ Whereis AddUser

AddUser:/usr/sbin/adduser/etc/adduser.conf/usr/share/adduser

/usr/share/man/man8/adduser.8.gz will search all binaries, manuals, and original code files.

Search only binary files

$ whereis-b AddUser

AddUser:/usr/sbin/adduser/etc/adduser.conf/usr/share/adduser questions about the-u parameter

This parameter, the man manual explains: Search for unusual entries. A file is said to be unusual if it

Does not have one entry of each requested type. Here is what is unusual, the author for the moment did not understand

The man manual also has instructions for using: Thus ' whereis-m-u * asks for those files in the current directory

which have no documentation. This is easier to understand, which means that the command "whereis-m-u" can be used to check

Find a file that does not have a document in the current directory.

The author in the/usr/sbin directory to execute this command, the results are also puzzling.

$ whereis-m-U *

ARP:/usr/share/man/man8/arp.8.gz/usr/share/man/man7/arp.7.gz
Chroot:/usr/share/man/man2/chroot.2.gz/usr/share/man/man8/chroot.8.gz
INVOKE-RC:
Nologin:/usr/share/man/man5/nologin.5.gz/usr/share/man/man8/nologin.8.gz
Tzconfig:
Update-bootsystem-insserv:
Update-locale:
UPDATE-RC:
UPDATE-RC:
Upgrade-from-grub-legacy:
Validlocale:

which the directory where the lookup command is located

, command format

which-a Command parameter meaning:

-a:all, lists all the matching paths.
• Command: Shell commands, such as LS, mkdir, etc.
Which this command is actually based on the directory of the environment variable path setting to find the first one to stop. If you add-a

parameter is searched, the directory of all path settings is traversed.

2. Command test

View the full path of the LS command

$ which LS

/bin/ls can see the LS command is under the bin, the system executes the LS command, is the execution of/bin/ls this file.

Find all matching paths

To better see the effect, the LS command is copied to the directory where the environment variable path is located, and the path value on the author's computer is:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games the LS command to copy

To/usr/games under:

$ cp/bin/ls/usr/games/ls Plus-a parameter test:

$ which-a ls

/bin/ls
/usr/games/ls can see that LS exists in two directories, so when the system executes the LS command, which one? Answer

is the first one.

Issues with CD commands

$ which CD in the test CD command, did not find the directory where this command, very strange. Later, using the type CD to view, found

The CD was originally built as a built-in command.


Summarize

Which this command parameter is not much, which involves the environment variable path and Whereis search for some command-related files, compared to which

, the author uses which more. About the-u parameter, if there are friends who know, thank you very much for informing

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.