Upgrade to Pro — share decks privately, control downloads, hide ads and more …

$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
Tweet

More Decks by Kim Schlesinger

Other Decks in Technology

Transcript

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

    View Slide

  2. @kimschles
    Has this ever
    happened to you?

    View Slide

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

    View Slide

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

    View Slide

  5. @kimschles
    Add it to your PATH

    View Slide

  6. @kimschles

    View Slide

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

    View Slide

  8. @kimschles
    Hi, I’m Kim

    View Slide

  9. @kimschles
    *nix

    View Slide

  10. @kimschles

    View Slide

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

    View Slide

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

    View Slide

  13. @kimschles
    Environment Variables
    ● Key value pairs that your system can access and use
    ● ALL_UPPERCASE
    Commands:
    ● env
    ● echo $ENV_VAR

    View Slide

  14. @kimschles
    Shell
    “A shell reads your commands and tells the OS to do things.”
    -- Julia Evans
    Source: https://twitter.com/b0rk/status/1218647766097940481

    View Slide

  15. @kimschles

    View Slide

  16. @kimschles

    View Slide

  17. @kimschles
    echo $shell

    View Slide

  18. @kimschles
    Bourne Shell
    /bin/sh

    View Slide

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

    View Slide

  20. @kimschles
    zsh
    /bin/zsh

    View Slide

  21. @kimschles

    View Slide

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

    View Slide

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

    View Slide

  24. @kimschles
    echo $PATH

    View Slide

  25. @kimschles

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  31. @kimschles
    Temporarily Edit PATH
    ● From the command line. Only lasts in current shell.
    PATH=$PATH:/usr/local/go/bin

    View Slide

  32. @kimschles
    Where did it go?
    which node

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  36. @kimschles
    ~
    Home Directory
    /
    Root Directory

    View Slide

  37. @kimschles
    ls /

    View Slide

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

    View Slide

  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

    View Slide

  40. @kimschles
    /bin
    /sbin
    /dev
    /etc
    /tmp
    /usr

    View Slide

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

    View Slide

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

    View Slide

  43. @kimschles

    View Slide

  44. @kimschles
    echo $PS1

    View Slide

  45. @kimschles
    PS1
    ● An environment variable
    ● Creates the default command prompt you see at the beginning of your
    command line.

    View Slide

  46. @kimschles
    \u@\h:\w\$

    View Slide

  47. @kimschles
    \u@\h:\w\$
    \u = username
    \h = hostname
    \w = working directory
    Separated with @, : and $

    View Slide

  48. @kimschles
    \u@\h:\w\$
    kschlesinger@kims-macbook-air:~$

    View Slide

  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.

    View Slide

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

    View Slide

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

    View Slide

  52. @kimschles
    Recap

    View Slide

  53. @kimschles
    $PATH

    View Slide

  54. @kimschles
    /bin and the
    Filesystem Hierarchy
    Standard

    View Slide

  55. @kimschles
    $PS1

    View Slide

  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?

    View Slide

  57. @kimschles
    /bin and FHS Resources
    ● Filesystem Hierarchy Standard
    ● Wikipedia: Filesystem Hierarchy Standard
    ● The /bin Directory
    ● Linux Directory Structure explained: /bin folder

    View Slide

  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

    View Slide

  59. @kimschles
    Blog post with links:
    https://kimschlesinger.com/2020/02/25/PATH-FHS-PS1/

    View Slide

  60. @kimschles
    kimschlesinger.com
    developdenver.org

    View Slide