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

Learn you some shell for your own good

Learn you some shell for your own good

A Shell introduction for the Ember/Web Developer

Mattia Gheda

July 03, 2014
Tweet

More Decks by Mattia Gheda

Other Decks in Technology

Transcript

  1. $ Learn you some shell for your own good (A

    shell introduction* for Ember developers) * absolutely non exhaustive ** some concepts might be simplified
  2. Let’s talk about the shell #!/bin/bash sh — shell, the

    standard command language interpreter (source $man shell)
  3. What is it and why should I care? * Main

    interface to the OS * It’s everywhere * You use it every day * Not just a task runner
  4. There’s not only one * sh - the beginning *

    bash (Bourne Again SHell) * zsh - it’s good * commands (like cd, ls, cp…)are separate * some commands can differ between Linux/OSX/bsd
  5. $ cd change (working) directory (if no directory given go

    to $HOME) ($HOME is your usually /home/user) ($HOME is aliased to ~)
  6. $ cd - go to previous directory every `cd` sets

    $OLDPWD to the last visited directory
  7. $ ls list directory contents * -lh (list nicely and

    human readable sizes) * -a (shows hidden files) * -t (sort by most recent)
  8. $ cp copy files (cp -r mydir destdir/) * -r

    recursive * copies mydir into destdir * beware OSX (cp mydir/ destdir/ copies content of mydir)
  9. $ cat concatenate files and print * get the content

    of a file immediately * useful for scripting * `dog` is a valid alternative (no kidding)
  10. $ less quickly read through a file * scroll around

    with keyboard * vim keys * less - opposite of more (from the man)
  11. $ tail output last part of a file * -n

    lines from end of file * -f keep waiting for updates * --pid=ID stops watching when pid dies
  12. $ df $ du monitor space usage of disk or

    directory * -h is your friend
  13. $ grep print lines matching a pattern * -r grep

    in files recursively * -i case insensitive (slow)
  14. $ pushd/popd - dirs change directory by using a stack

    * pushd `cd` and pushes it onto the stack * popd pops the first one and `cd` to i * dirs shows the current stack * cd +N -N
  15. * kill prev word * kill prev char * kill

    next char ctrl-w ctrl-h ctrl-d
  16. edit current line in $EDITOR * you can set a

    default editor for the terminal * great for complex commands ctrl-x ctrl-e
  17. 3: Edit the line it’s ok to make mistakes *

    psss: there’s a vim mode too...
  18. kills current process * easy way out * sends SIGINT

    * (it’s actually way more complicated than that) ctrl-c
  19. suspend current process * returns you to the shell *

    process is “on-hold” * sends SIGTSTP ctrl-z
  20. sends <command> to the background * you can also suspend

    and then call ‘bg’ $ <command> &
  21. $ ps $ top know your processes * ps aux

    | print list of processes * top | interactive interface * htop | fancier top
  22. ...

  23. > redirect output to file * >> redirects and appends

    to file * cat filename >> otherfile
  24. | “pipe” the output of a program into the input

    of another $ ls -l | grep -i name
  25. $ autojump $ fast remember where you cd gets you

    there fast * j fuzzymatchagainstpath
  26. $ screen $ tmux multiplex your terminal * great for

    servers * even better for development * tiling is good
  27. $ tmate tmux based pairing env * insanely good *

    (you need to use a terminal editor)