How to check a path in Unix: 3 steps

Table of contents:

How to check a path in Unix: 3 steps
How to check a path in Unix: 3 steps

You have certainly happened to receive an error message such as

command not found by issuing a command in a terminal under Unix or Linux. This terse message means that the command you want to issue is not recognized by the system, and there can be three reasons for this:

because she does not exist, because you have committed a typo by entering his name, or because the directory where it is located is not listed in the PATH variable of your system.


Check Path in Unix Step 1

Step 1. Use the command correctly

When you enter an instruction in a terminal, the runtime environment or shell will search for it first among the built-in commands of the system (usually in the directories whose name is bin Where sbin), then if it does not find it there, in the directories registered in the variable PATH.

  • Enter echo $ PATH to display the content of the variable PATH.

    Check Path in Unix Step 1Bullet1
    • $ echo $ PATH

      (without including the first symbol "$").

      You will get a response similar to:

      • / sbin: / usr / sbin: / bin: / usr / bin: / usr / X11R6 / bin: / usr / local / sbin: / usr / local / bin

Check Path in Unix Step 2

Step 2. Don't forget the “$” symbol in front of PATH

Otherwise, the system would only print "


»In response to the command echo instead of displaying the list of paths registered in the PATH variable, separated between them by a " : ».

Check Path in Unix Step 3

Step 3. Find the location of an order

Use which Where type To find out in which directory a command is located:

  • $ which ifconfig

    should display:
  • / sbin / ifconfig
  • $ type ifconfig

    will answer you:
  • ifconfig is / sbin / ifconfig


  • On Unix-like systems like Linux and BSD, the default behavior of the shell is not to look for a command in the current directory unless the current directory is entered in the variable. PATH of the system. You can remedy this situation by adding a period (“.”) To the variable PATH, which symbolizes the current directory under Unix. Go to your home directory / home / user where you can edit the file .profile. Use any text editor like vi or nano to open, edit, and save this file. Note that this file, whose name is preceded by a period, is invisible. You can enter directly

    vi ~ /.profile

    to edit it.
  • If you want to execute a command located in the directory where you are located, precede it with a period followed by the slash character “./”. If this command is called myprogram, enter

    ./my program

    to run it.

Popular by topic