$PATH, /bin and $PS1

$PATH, /bin and $PS1

In this talk, Kim demystifies the $PATH variable, which is often a part of installing new dev tools, she will describe how your computer stores executable files in your /bin directory, and the Filesystem Hierarchy Standard that governs the root directory, and she’ll show you how to customize your command line by altering the $PS1 variable.

This talk is for people who use a terminal to run commands and want to learn more about what’s going on and how to customize their command-line interface.

There is a companion blog post to this talk at https://kimschlesinger.com/2020/02/25/PATH-FHS-PS1/


Kim Schlesinger

February 25, 2020


  1. @kimschles $PATH, /bin and $PS1 Kim Schlesinger DenverScript, February 2020

  2. @kimschles Has this ever happened to you?

  3. @kimschles Source: Installing node.js on macOS Mojave, macOS Sierra and

    earlier OSX
  4. @kimschles “make sure that /usr/local/bin is in your path..”

  5. @kimschles Add it to your PATH

  6. @kimschles

  7. @kimschles $PATH, /bin and $PS1

  8. @kimschles Hi, I’m Kim

  9. @kimschles *nix

  10. @kimschles

  11. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  12. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  13. @kimschles Environment Variables • Key value pairs that your system

    can access and use • ALL_UPPERCASE Commands: • env • echo $ENV_VAR
  14. @kimschles Shell “A shell reads your commands and tells the

    OS to do things.” -- Julia Evans Source: https://twitter.com/b0rk/status/1218647766097940481
  15. @kimschles

  16. @kimschles

  17. @kimschles echo $shell

  18. @kimschles Bourne Shell /bin/sh

  19. @kimschles Born Again Shell AKA BASH /bin/bash

  20. @kimschles zsh /bin/zsh

  21. @kimschles

  22. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  23. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  24. @kimschles echo $PATH

  25. @kimschles

  26. @kimschles /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

  27. @kimschles /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin • Environment Variable • 1 long string •

    Colon-separated • Is a path to executable code invoked through text commands
  28. @kimschles /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin

  29. @kimschles Permanently Edit PATH • Update PATH in .bashrc, .bash_profile

    or .zshrc file • /usr/local/go/bin export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  30. @kimschles Permanently Edit PATH • Update PATH in .bashrc or

    .bash_profile file • /usr/local/go/bin export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin
  31. @kimschles Temporarily Edit PATH • From the command line. Only

    lasts in current shell. PATH=$PATH:/usr/local/go/bin
  32. @kimschles Where did it go? which node

  33. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  34. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  35. @kimschles /bin • bin stands for binary, which is a

    file you can execute • A collection of scripts • /bin has the basic commands we use like cat, mkdir, echo, pwd, rm
  36. @kimschles ~ Home Directory / Root Directory

  37. @kimschles ls /

  38. @kimschles Source: https://en.wikipedia.org/wiki/Unix_filesystem#/media/File:Standard-unix-filesystem-hierarchy.svg

  39. @kimschles “The Filesystem Hierarchy Standard (FHS) defines the directory structure

    and directory contents in Linux distributions. It is maintained by the Linux Foundation. The latest version is 3.0, released on 3 June 2015.” Source: https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
  40. @kimschles /bin /sbin /dev /etc /tmp /usr

  41. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  42. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  43. @kimschles

  44. @kimschles echo $PS1

  45. @kimschles PS1 • An environment variable • Creates the default

    command prompt you see at the beginning of your command line.
  46. @kimschles \u@\h:\w\$

  47. @kimschles \u@\h:\w\$ \u = username \h = hostname \w =

    working directory Separated with @, : and $
  48. @kimschles \u@\h:\w\$ kschlesinger@kims-macbook-air:~$

  49. @kimschles Add colors (and emojis) Open you .bash_profile, .bashrc or

    .zshrc file and Add ANSI color escape sequences before each section of your PS1. Add emojis if you’d like.
  50. @kimschles export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h: \[\033[33;1m\]\w\[\033[m\]\$ "

  51. @kimschles Agenda 1. Key Terms 2. $PATH 3. /bin 4.

  52. @kimschles Recap

  53. @kimschles $PATH

  54. @kimschles /bin and the Filesystem Hierarchy Standard

  55. @kimschles $PS1

  56. @kimschles $PATH Resources I’ve learned alot about the PATH variable

    from Breanne Boland, who wrote the first two articles on this list. • Access & Make Awesome Your PATH System Variable • When laziness is efficient: Make the most of your command line • PATH Definition • How to Modify the Shell Path in macOS Sierra and OSX using Terminal • What is the difference between .bash_profile and .bashrc?
  57. @kimschles /bin and FHS Resources • Filesystem Hierarchy Standard •

    Wikipedia: Filesystem Hierarchy Standard • The /bin Directory • Linux Directory Structure explained: /bin folder
  58. @kimschles $PS1 Resources • How to Customize Shell Variable PS1-PS4

    on Bash Prompt • UNIX StackExchange: Colorizing your terminal and shell environment • My Mac OSX Bash Profile • StackOverflow: List of ANSI color escape sequences • Simple Tricks to Improve the Terminal Appearance in Mac OS X • Customize the colors of your Terminal in Mac OS X
  59. @kimschles Blog post with links: https://kimschlesinger.com/2020/02/25/PATH-FHS-PS1/

  60. @kimschles kimschlesinger.com developdenver.org