# The PATH Variable — Linux

Source: https://www.geekswithgeeks.com/en/linux/linux-path-variable

> How the shell finds the program behind a command.

## PATH is a search list

`PATH` is a colon-separated list of directories. When you type `ls`, the shell searches each directory in `PATH`, in order, for a matching executable.

## Viewing and extending PATH

Add a directory of your own scripts so you can run them by name from anywhere.

```bash
echo $PATH
export PATH="$HOME/scripts:$PATH"
```

Output:

```
/usr/local/bin:/usr/bin:/bin
```

**Quiz:** If two directories in PATH both have a program called `foo`, which one runs?

- [x] The one found in the first matching directory
- [ ] Both run together
- [ ] Linux picks randomly

*Answer:* The one found in the first matching directory. The shell searches PATH directories in order and stops at the first match.
