• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to fix bash:command not found error in Linux/Unix

    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.
    Well in this post I will help you out and prepare you for both the possibilities.

    Suppose you are getting an error
    # useradd deepak
    -bash: useradd: command not found

    This happens generally when the path variable for that command is not defined. So in that case you will have to manually define the path variable. This error is command independent, so any time you face this issue kindly check for the location of the command and add the complete path to PATH variable.

    There are few methods which you can use to find the location of the missing command
    Method 1
    Look out for the missing command using
    # whereis useradd
    useradd: /usr/sbin/useradd /usr/share/man/man8/useradd.8.gz

    Method 2
    You can also use the below command but this might not work all the time because ultimately this command uses .bash_profile and .bashrc for all the saved PATH variable of all the executable file

    # which useradd

    Method 3
    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
    # export PATH=/usr/sbin:$PATH
    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

    To make permanent changes in your machine, add this command to your .bash_profile
    # 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.

    Permanent Fix:

    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.
    export PATH=$PATH:/usr/bin:/usr/sbin:/usr/local/bin:/usrlocal/sbin
    Now in case you do not find the useradd file in your machine or even after adding the PATH variable you are getting some error then there is a possibility that related rpm package has corrupted and you need to re-install that package.

    Now how are you going to find the package name responsible for "useradd"

    You can use yum to check the rpm file responsible for this executable file.

    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

    Solution 1
    Then run the below command
    $ rpm -qf /usr/sbin/useradd

    As you see the package responsible for useradd binary file is shadow-utils

    Solution 2
    # yum whatprovides  */useradd
    shadow-utils- : Utilities for managing accounts and shadow
                                      : password files
    Repo        : base
    Matched from:
    Filename    : /etc/default/useradd
    Filename    : /usr/sbin/useradd
    As you can see shadow-utils- is the rpm file which can help you re-install "useradd"

    Now you can manually install this rpm file
    # yum -y install shadow-utils

    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 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?

    Deepak Prasad

    Deepak Prasad is a techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+

    Do you also have something to share here?

    Become an author and be a part of our GoLinuxHub Team, Click here for more information
    How to fix bash:command not found error in Linux/Unix How to fix bash:command not found error in Linux/Unix Reviewed by Deepak Prasad on Friday, September 28, 2012 Rating: 5

    No comments:

    Powered by Blogger.