Learn a Linux command every day (51): which

Time:2021-9-22

Learn a Linux command every day (51): which

Yesterday’s recommendation:Learn a Linux command every day (50): Date

Command introduction

The which command is used to find and display the absolute path information of the specified command, and find the path by the environment variable path. You can also see whether a system command exists by using the which command.

Syntax format

which [options] [--] programname [...]

Option description

-a   # Print all matching pathnames for each matching file name
-V   # Print version information

Which exit status

0  # All file names were found and all files are executable
one  # One or more file names cannot be found or are not executable
two  # The specified option is invalid

Application examples

Displays the full path of the command

[[email protected] ~]# which which
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
 /usr/bin/alias
 /usr/bin/which
[[email protected] ~]# which ls
alias ls='ls --color=auto'
 /usr/bin/ls
[[email protected] ~]# which pwd
/usr/bin/pwd
[[email protected] ~]# which rz
/usr/bin/rz
[[email protected] ~]# which ifconfig
/usr/sbin/ifconfig

Learn a Linux command every day (48): Top

Learn a Linux command every day (49): Free