Skip to Main Content
Ubuntu: Up and Running
book

Ubuntu: Up and Running

by Robin Nixon
April 2010
Beginner content levelBeginner
464 pages
12h 7m
English
O'Reilly Media, Inc.
Content preview from Ubuntu: Up and Running

The PATH Environment Variable

Many commands you enter at the command line require the use of an external program that is loaded from the filesystem. For example, commands such as mkdir and wc actually reside in the /bin folder.

Whenever you enter an instruction that Bash doesn’t recognize, it tries executing it as a program and returns an error if no program of the same name is found. And this doesn’t only include the main commands we’ve been looking at, because you can run almost any program from the command line.

But with a filesystem comprising thousands of files, how does Ubuntu know which programs to run and from which directories? The answer is that it uses a system environment variable to point to a subset of folders it must search upon receipt of an unknown command. This variable is called PATH, and it can be displayed using the echo command, like this (the $ symbol is required):

echo $PATH

The result of issuing this command will look something like the following seven absolute folder paths, separated by colons:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Each time an unknown command is entered, Ubuntu will search each of the folders in the path in the order they are provided to try and find a program of the same name. If one is found, it is executed; otherwise, an error message is displayed.

These seven folders provide easy access to all the main programs in the operating system, including the games. But any programs that are not located in one of these ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ubuntu Made Easy

Ubuntu Made Easy

Rickford Grant, Phil Bull
Ubuntu for Non-Geeks, 4th Edition

Ubuntu for Non-Geeks, 4th Edition

Rickford Grant, Phil Bull
CentOS Quick Start Guide

CentOS Quick Start Guide

Shiwang Kalkhanda

Publisher Resources

ISBN: 9781449382827Errata Page