How to find command location in Linux and Unix
This is a small how to on finding your command location. Some times it’s required to find command location to use it as path is not set properly to /bin or /sbin or some other folder. And some times we install packages through scripts where the commands will be installed in a defined path other than /usr/bin or /usr/sbin etc.
command to check where the particular command is installed?
which command-name
Example:
which ls
Output:
root@surendra:/home/surendra# which ls
/bin/ls
root@surendra:/home/surendra#
How about getting with other command along with manual pages?
whereis command-name
Example:
whereis ls
Output:
root@surendra:/home/surendra# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
root@surendra:/home/surendra#
some times we don’t know where the command is located but still we want to use it, at these times you can use which command to give entire path
`which ls`
or
$(which ls)
the above two are very much handy when writing shell scripts when you are not aware/sure where the command located. Please share your thoughts on how you avoid this situation.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018