2.5 Command Path

2.5.1 Command path

Every command is program. Each program is a kind of files and it is located to directories for programs, such as /bin and /sbin.

2.5.2 Display command path (which)

When executing a basic command, we do not need to know where the program is. This is because the directory where the program is located is set in the environment variable called PATH. 'which' command shows us which directory in PATH environment variable has the command program.


which command-name

Practice: Display command path

Let's check the command path of cat command.

$ which cat ↵
/bin/cat        cat command exists under /bin directory

If the directory where the command resides is not included in the PATH environment variable, the which command results an error. For example, the general user does not set the path (there are some distributions being set) to the commands that require administrator privileges, the path can not be checked by 'which'.

$ which ifconfig ↵
/usr/bin/which: no ifconfig in (/usr/local/bin:/bin:/usr/bin)
Since ifconfig command is under /sbin which requires administrator authority, general user can not check it.

In order to confirm the value of environment variable PATH, we use env command.

$ env | grep PATH ↵

Previous Next