Check Path in Unix

Ever type in a simple command and get an error?

  • $ woot
  • bash: woot: command not found

Then the command is not in your PATH, or simply doesn't exist on your system.

Steps

  1. Use the right command. When you type in a command, the shell searches itself for built-in commands, then it searches the directories listed in your PATH variable.
    • To check PATH, type "echo $PATH".
      • $ echo $PATH
        • /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin
  2. Include the dollar sign, or the shell will just print "PATH" to your screen.) This shows the directories checked, separated by colons.
  3. To find the location of a command, use the "which" or "type" commands:
    • $ which ifconfig
    • /sbin/ifconfig
    • $ type ifconfig
    • ifconfig is /sbin/ifconfig



Tips

  • By default, the shell does not search your current directory in Unix-type OSes (BSD, Linux, etc.) unless it's already in your path. This can be fixed by adding a period (dot), which is the Unix short-cut for the current directory. This can be changed by going to your home directory. This should contain '.profile'. Use an editor, such as vi, to open, change, and save.

Warnings

  • As always, be careful what you do while logged in as root.

Related Articles