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 full-size slide

  2. @kimschles
    Has this ever
    happened to you?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  5. @kimschles
    Add it to your PATH

    View full-size slide

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

    View full-size slide

  7. @kimschles
    Hi, I’m Kim

    View full-size slide

  8. @kimschles
    *nix

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. @kimschles
    echo $shell

    View full-size slide

  14. @kimschles
    Bourne Shell
    /bin/sh

    View full-size slide

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

    View full-size slide

  16. @kimschles
    zsh
    /bin/zsh

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. @kimschles
    echo $PATH

    View full-size slide

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

    View full-size slide

  21. @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 full-size slide

  22. @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 full-size slide

  23. @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 full-size slide

  24. @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 full-size slide

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

    View full-size slide

  26. @kimschles
    Where did it go?
    which node

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  29. @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 full-size slide

  30. @kimschles
    ~
    Home Directory
    /
    Root Directory

    View full-size slide

  31. @kimschles
    ls /

    View full-size slide

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

    View full-size slide

  33. @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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  37. @kimschles
    echo $PS1

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  42. @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 full-size slide

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

    View full-size slide

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

    View full-size slide

  45. @kimschles
    Recap

    View full-size slide

  46. @kimschles
    $PATH

    View full-size slide

  47. @kimschles
    /bin and the
    Filesystem Hierarchy
    Standard

    View full-size slide

  48. @kimschles
    $PS1

    View full-size slide

  49. @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 full-size slide

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

    View full-size slide

  51. @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 full-size slide

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

    View full-size slide

  53. @kimschles
    kimschlesinger.com
    developdenver.org

    View full-size slide