PATH, FHS and $PS1

This is a companion blog post for a presentation I gave at the February 2020 DenverScript Meetup.

You can find the video recording and slide deck on my talks page.

The Path Variable

  • PATH is an enviornment variable.

  • The variable is a colon-delimited string. The directory before each colon contains executable code and is invoked through a command, like pwd.

  • To see the value, run echo $PATH from your command line

  • Here’s an example path:


  • In the example, these are the directories in the path:

    • /usr/local/sbin
    • /usr/local/bin
    • /usr/sbin
    • /usr/bin
    • /sbin
    • /bin
  • When you type a text command and hit RETURN your computer looks in all the directories listed in the path, and if it finds code for the command, it will execute the program.

  • Most of the built-in system commands are written in the C programming langauge.

  • For MacOS and Linux, to change your path, find and edit it in your .bash_profile, .bashrc or .zshrc file.


I’ve learned alot about the PATH variable from Breanne Boland, who wrote the first two articles on this list.

The Filesystem Hierarchy Standard

  • The root directory contains folders and files under the forward-slash, /.
  • The Filesystem Hierarchy Standard defines the organization of the root directory.
  • Most Unix-like operating systems (UNIX, Linux, MacOS, etc.) organize their root directories according to the FHS.

A few directories in the root directory:

  • /bin: stands for binary, and contains common commands used by system adminstrators and users
  • /sbin: stands for system binaries, andontains root-only commands and commands that pair well with commands in /bin
  • /usr: has some read-only data, and lots of common commands in /usr/bin



The PS1 Variable

  • PS1 is an enviornment variable that creates the default command prompt you see at the beginning of your command line.

  • To see the value, run echo $PS1.

  • Here’s an example PS1:


  • In the example, the username (\u), hostname (\h) and working directory (\w) come before the dollar sign, and are separated by @ and :.

  • On my computer, this PS1 shows up as kschlesinger@kims-macbook-air:~$

  • To add colors to your PS1, open your bash_profile, .bashrc or .zshrc and add ANSI color escape sequences before each section of your PS1. Add an emoji if you’d like. Here’s an example:

    export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ 🌵 "

  • On my computer, this PS1 shows up as kschlesinger@kims-macbook-air:~$ 🌵 with the username in teal, the hostname in green and the working directory in yellow.