One Linux command per day (which) command

Source: Internet
Author: User
Tags aliases echo command function definition stdin

the which command is used to find and display the absolute path of a given command.

environment variable The directory that you need to traverse when you save the Find command in path. The which directive looks for eligible files in the directory where the environment variable $path is set. That is, with the which command, you can see whether a system command exists, and the command that executes exactly which location.

(1) Usage:

Usage: which [option parameter] [command name]

(2) Function:

Features: Finding files in environment variables

(3) option Parameters:

1)-n Specifies the length of the file name, which must be greater than or equal to the longest file name in all files.

2)-P is the same as the-n parameter, but the path to the file is included here.

3)-W Specifies the width of the field at the output.

4)-V Display version information

(4) Example:

1) [[email protected] sunjimeng]# which PWD view the directory where the command is located

[[email protected] sunjimeng]# which pwd/usr/bin/pwd[[email protected] sunjimeng]# which head/usr/ bin/Head[[email protected] sunjimeng]# which cat/usr/bin/cat
[email protected] sunjimeng]# which adduser/usr/sbin/adduser

2) [[email protected] sunjimeng]# which which use which command to find which command

[[Email protected]t sunjimeng]# which whichalias which='alias |/usr/bin/which--tty-only-- Read-alias--show-dot--show-tilde'    /usr/bin/alias    /usr/bin/which

3) [[email protected] sunjimeng]# which--help

[email protected] sunjimeng]# which--Helpusage:/usr/bin/which [Options] [--] COMMAND [...]  Write the full path of COMMAND (s) to standard output. --version,-[VV] Print version and exit successfully. --help, Print ThisHelp and exit successfully. --skip-dot Skip DirectoriesinchPATH, start with a dot. --skip-tilde Skip DirectoriesinchPATH, start with a tilde. --show-dot Don't expand a dot to current directory in output.--show-tilde Output a tilde forHOME Directory fornon-Root. --tty-only Stop processing options on the rightifNot on TTY. --all,-a Print all matchesinchPATH, not just the first--read-alias,-I read list of aliases fromstdin. --skip-alias Ignore option--read-alias; Don't read stdin.--read-functions Read Shell functions fromstdin. --skip-functions Ignore option--read-functions; Don't read stdin.Recommended Use isTo write the output of (alias; declare-f) to Standardinput, so, which can show aliases and shell functions. See which (1) forexamples. If the Options--read-alias and/or--read-functions is specified then Theoutput can is a full alias or function definition, optionally followed bythe full path of each command used inside of those. Report Bugs to<[email Protected]>.

4) [[email protected] sunjimeng]# which--version

 [[email protected] sunjimeng]# which--versiongnu which v2.  20 , Copyright (C) 1999 -2008   Carlo Wood.gnu which comes with absolutely NO WARRANTY; This program  is  free   software; Your freedom to use, Changeand distribute  this  program is  protected  by the GPL. 
[email protected] sunjimeng]# which-Vgnu which v2.  - 1999  -   is-free, protected by the GPL.

5) Other:

Description

1.which is based on the user's configured directory within the PATH variable to search for a running file! Therefore, the different PATH configuration content found the command of course not the same!

2. There will be two which, one of which is alias. This is called the "command alias", meaning that the input which will wait for the next sequence of commands!

3.bash built-in commands:

1). What is the build in command:

The shell built-in command refers to commands in the bash (or other versions) toolset. There is usually a system command with the same name, such as the echo command in bash and the/bin/echo are two different commands, although they are roughly similar in their behavior. When you type a command in bash, the system will first see if he is a built-in command, and if not, see if it is a system command or a third-party tool. So typing the echo command in bash actually executes the Bash command in the Bash toolset, which is the built-in command instead of/bin/echo the system command.

2). Built-in command and system command built-in commands have higher execution efficiency than system-theory commands. External commands often need to fork out (produce) a sub-process, while the built-in commands are generally not used.

3). View whether a command is a system command or a built-in command: type

[[Email protected] sunjimeng]# type-/usr/bin//bin/-/usr/bin//bin/ Echo

As you can see, some commands, Echo and PWD are both built-in commands and system commands.

4. Supplement:

We often find a file in Linux, but do not know where to put it, you can use some of the following commands to search:
Which view the location of the executable file.
Whereis View the location of the file.
Locate to view the file location with the database.
Find actual search hard disk query file name.

One Linux command per day (which) command

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.