In Linux and Unix systems, commands are executable files. The commands may be specific with user environment.We can set the absolute path of specific command as per user in environment.If we require the information, to get the absolute path of command. In that case we will use
To find the absolute path of command in Linux/Unix system, we use
which command-name OR which executable-file-name
echo $PATH command will show the directory path. The
which command, locate the command from these directories.
[email protected]:/# echo $PATH /usr/local/rvm/gems/ruby-2.1.0/bin:/usr/local/rvm/gems/[email protected]/bin:/usr/local/rvm/rubies/ruby-2.1.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/rvm/bin [email protected]:/#
Example : In this example,we will find the absolute path of useradd command.
The output from which command is showing the absolute path.
[email protected]:/# which useradd /usr/sbin/useradd [email protected]:/#
Print multiple command’s absolute path
We can use multiple arguments in
which command. Hence,we can show two or more executable files absolute path on terminal.
which command-1 command-2 command-N
Example: In this example,we are finding the absolute path of ls,chown,chgrp and usermod command.
[email protected]:/# which ls chown chgrp usermod /bin/ls /bin/chown /bin/chgrp /usr/sbin/usermod [email protected]:/#
print all matching pathnames of each argument
To print all matching pathnames of each argument,we use -a option with arguments i.e command name.
which -a argument
Example: In this example, we are searching absolute path of echo command
[email protected]:/# which -a echo /usr/sbin/echo /bin/echo [email protected]:/#