How to find the location of commands in Linux?

This post is for those who use the various commands available in Linux but they are not exactly aware of the location of those commands.

Basically those commands we use in Linux are configured in binary language. If you try to read any of those files using any editor then you won't understand any thing as it is not human readable. These all commands are installed along with the relative packages with the installation of OS.
But well returning to the topic as most of us know that mostly all the required commands are placed in /bin, /usr/bin, /sbin and /usr/sbin.

But how do you check whether the command you are using is in which of the above location. The first method would be you manually search in all those locations using any of the find command.

Secondly you can use which command, It will show you the location of the command along with alias entry if any assigned for that command.

# which "command_name"

For eg:

# which cp
alias cp='cp -i'
/bin/cp

# which useradd
/usr/sbin/useradd
In case you get the below error# which samba
/usr/bin/which:
no samba in (/usr/lib/qt-3.3/bin:/usr/local/sbin
/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
It means your PATH variable does not contains the path for samba command. In that case which will not help you find the location of the command.

So, you can use the below command for the same purpose
# whereis command_name
For example
# whereis useradd
useradd: /usr/sbin/useradd /usr/share/man/man8/useradd.8.gz

I hope I made my self clear

Related Articles
How to set environment (PATH) variable permanently in Linux
How to mount windows share on linux

Follow the below links for more tutorials:

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?