In my last article I had shared the instructions which can be used to check the path of any command on your Linux machine so that you do not end up with this error
Most of you must have been facing this issue. Actually this can not be considered as as error until and unless the package file for the command is missing or has corrupted due to some reason because in that case you might have to re-install the package.
# useradd deepak
-bash: useradd: command not found
# whereis useradd
useradd: /usr/sbin/useradd /usr/share/man/man8/useradd.8.gz
# which useradd
You can use find command ultimately to look out for the missing command or file (As all the command are executable files)
# find / -name useradd -type f
So now once you got the location of the command, add the path to the PATH variable
But again running this export command will be session dependent so once you change the session you will again have to export the new PATH variable
# vi /root/.bash_profile
export PATH=/usr/sbin:$PATH So now every time your system reboots this command will be executed and the PATH variable will be updated.
To fix this issue permanently so that this issue does not comes up again. You can add the default location of all the directories in the PATH variable which contains all the executable files in Red Hat Linux in your .bash_profile file.
You should also read the difference between .bash_profile and .bashrc, so that you can use the file wisely?
NOTE: The following commands are tested on RedHat and CentOS
First find the full path of the executable file using the below command or any of the command shown above
# which useradd
Then run the below command
$ rpm -qf /usr/sbin/useradd
As you see the package responsible for useradd binary file is shadow-utils
# yum whatprovides */useradd
2:shadow-utils-220.127.116.11-13.el6.i686 : Utilities for managing accounts and shadow
: password files
Repo : base
Filename : /etc/default/useradd
Filename : /usr/sbin/useradd
# yum -y install shadow-utils