Last active 6 months ago

slides.md Raw
 __  __           _                   _ _                  
|  \/  | ___   __| | ___ _ __ _ __   | (_)_ __  _   ___  __
| |\/| |/ _ \ / _` |/ _ \ '__| '_ \  | | | '_ \| | | \ \/ /
| |  | | (_) | (_| |  __/ |  | | | | | | | | | | |_| |>  < 
|_|  |_|\___/ \__,_|\___|_|  |_| |_| |_|_|_| |_|\__,_/_/\_\
                                                           
      _ _   _              _     
  ___| (_) | |_ ___   ___ | |___ 
 / __| | | | __/ _ \ / _ \| / __|
| (__| | | | || (_) | (_) | \__ \
 \___|_|_|  \__\___/ \___/|_|___/
                                 

Target audience

  • linux desktop CLI users
  • linux admins
  __________________________________________
 / This is the year of linux on the desktop \
|                                            |
|          ...Windows10 has WSL ;-)          |
 \                                          /
  ------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Linux tooling philosophy

  • do one thing (and only one thing!) well

  • chaining

  • sound familiar? (hint: functional programming...)


Why? Improvements to...

  • productivity

  • optics

    • "unix porn" (PS1, ls, ...)

Learn the basics

  • emacs and vim

    • learn navigation, copy & paste, (and how to exit 👍)
    • pick one and become fluent
  • cd, ls, cat, less, find, grep, sed, tail, awk, dd, rsync, ...

  • Combine using pipes ( | ) and redirection ( > )


terminals and shells

What is the difference between terminal and shell?

+--------------------+
|     "terminal"     |
+--------------------+
|                    |
| +--------------+   |
| |              |   |
| |    "shell"   |   |
| |              |   |
| +--------------+   |
|                    |
+--------------------+

--

terminals and shells

terminal

  • colors (16 or more), fonts (utf8, ligatures, ...)
  • interactions
    • keyboard shortcuts
    • mouse interaction (copy & paste, scrolling, selection, ...)

shell

  • everything else (f.ex. PS1, scripting language)

--

terminal

What is the best terminal?

  • use your default

Unicode, Emojis, Fonts, Image support (!)

  • but think about enriching your output!

  • Emojis: 👍 ✅ 💥 ✌ 💩 💬 🌩 🌟


shell

  • bash
  • zsh
  • fish
  • dash (embedded)

--

shell / zsh

--

shell / fish: The new kid on the block

--

shell / bash


shell / PS1

PS1: alias for "prompt"

  • default: username:/some/location$
  • $PWD present working directory

Extra, nice-to-have information

  • only show relevant parts (hide user/machine name on local machine)
  • compact location ( $PWD )
  • git status
  • environment infos (node / .NET / Java / Python / etc version)

--

shell / PS1: liquidprompt

simple prompt

--

shell / PS1: Powerline

started as fancy statusline for vim …

--

shell / PS1: Starship

the new kid on the block


Command-Line Operators and What They Do

--

Ampersand Operator (&)

$ sleep 5 &
[1] 301161
  • command is executed in the background
  • shell is freed

--

Semicolon Operator (;)

$ pwd; mkdir /tmp/test; cd /tmp/test; touch foo; readlink -f foo
/tmp
/tmp/test/foo
  • chaining execute commands in a defined, sequential order
  • independend from exit code

--

OR Operator (||)

$ false || uptime
 11:21:53 up 20 days,  2:30,  1 user,  load average: 0,36, 0,35, 0,46
  • following command only executed if preceding command fails (exit 0)

--

Pipe Operator (|)

$ lspci | grep -E "(Network|Ethernet)"
00:14.3 Network controller: Intel Corporation Comet Lake PCH-LP CNVi WiFi
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (10) I219-V
  • directs output of preceding command as input to succeeding command

--

AND Operator (&&)

$ pwd && mkdir /tmp/test && cd /tmp/test && touch foo && readlink -f foo
/tmp/test
mkdir: cannot create directory '/tmp/test': File exists
$ pwd && mkdir -p /tmp/test && cd /tmp/test && touch foo && readlink -f foo
/tmp/test
/tmp/test/foo
  • following command only executed if preceding command was successfully executed (exit 1)

--

NOT Operator (!)

$ ls !(*.txt)
foo
  • works similar to except statement in programming

--

Precedence Operator ((..))

$ (true && false) && (false || true) || echo "Did exit with false"
Did exit with false
  • used for grouping and precedence of the execution sequence
  • inside parentheses, starts subshell

--

Combination Operator ({..})

$ [ -f hello.txt ] && echo "file exists" ; echo "hello"
hello
$ [ -f hello.txt ] && { echo "file exists" ; echo "hello"; }
  • commands are run (or not run) as a whole

--

Concatenation or the Escape Operator (\)

$ echo "Hello! from the\
> other side"
Hello! from theother side
$ touch test\(1\).txt
$ ls test\(1\).txt
'test(1).txt'
  • concatenate large commands over several lines
  • escape character when working with strings

--

Redirection Operators (>, >>, <)

$ echo "dsd" > test; echo "bssss" >> test; cat test
dsd
bssss
$ sort < test
bssss
dsd
$ echo "blah" > test; cat test
blah

--

References


Tools

You where waiting for

--

tldr

  • 41k stars https://tldr.sh/

  • man pages can be difficult

  • tldr: implemented in many languages (js, ruby, python, perl, haskell, etc)

  • Demo: ln, tar, scp

--

McFly

McFly replaces your default Ctrl R shell history search with an intelligent search engine that takes into account your working directory and the context of recently executed commands. McFly’s suggestions are prioritized in real time with a small neural network

--

thefuck

fix common typos / mistakes

--

The GNU Midnight Commander

mc is a visual shell much like a file manager, only with many more features

  • text mode application, but it also includes mouse support
  • best features are its ability to FTP, view tar and zip files, and to poke into tar, ar, deb, zip, cpio, lha and rar for specific files

--

bat

cat & less with syntax highlighting

bat looks good on a dark background by default. However, if your terminal uses a light background, some themes like GitHub or OneHalfLight will work better for you.

  • category: read / file display

--

ripgrep

very fast grep replacement

  • 33.7k stars https://github.com/BurntSushi/ripgrep

  • ripgrep recursively searches directories for a regex pattern

  • sensible defaults: respect .gitignore, ignores hidden files & folders

  • command: rg

  • use rg hidden g '!.git' "your search" to search all hidden folder except .git

  • category: search

--

ripgrep-all

ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, sqlite (!), etc

--

fzf

interactive fuzzy search

  • 47.5k stars https://github.com/junegunn/fzf
  • pipe any line based input to fzf: Example find * -type f | fzf
  • good integration with other tools
  • nice helper methods for
    • files & directories cd **<TAB>
    • kill kill -9 <TAB>
    • host names ssh **<TAB>
    • environment variables & aliases unset **<TAB>, export **<TAB>, unalias **<TAB>
  • category: search
  • Demos:
    • find files and select them
    • search a text file

--

fd

simple alternative to find

  • "The command name is 50% shorter than find"
  • Convenient syntax fd PATTERN (instead of find -iname '*PATTERN*')
  • Sensible defaults: .gitignore, ignore hidden files/folders
  • fast
  • category: search

--

hyperfine

benchmarking tool

# comparing `fd` with `find`

# ubuntu uses `fdfind` by default
hyperfine --warmup 3 'fdfind -HI '.*[0-9]\.jpg$'' 'find ~ -iregex '.*[0-9]\.jpg''

# arch
hyperfine --warmup 3 'fd -HI '.*[0-9]\.jpg$' Documents/talks' 'find Documents/talks -iregex '.*[0-9]\.jpg$''

# unfair comparison: `fd` ignores hidden files and `.git` be default
hyperfine --warmup 3 'fd '.*[0-9]\.jpg$' Documents/talks' 'find Documents/talks -iregex '.*[0-9]\.jpg$''
  • category: benchmarking

--

progress

monitor any kind of "copy"

No command currently running: cp, mv, dd, tar, cat, rsync, grep, fgrep, egrep, cut, sort, md5sum,
sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, adb, gzip, gunzip, bzip2, bunzip2, xz,
unxz, lzma, unlzma, 7z, 7za, zcat, bzcat, lzcat, split, gpg, or wrong permissions.
  • Demo:
    • ~/tmp/demo/origin/ contains very large file
    • tmux split screen ~/tmp/demo/
    • copy from ~/tmp/demo/origin/* to ~/tmp/demo/destination/ using cp.
    • watch progress

--

Ultimate Plumber (up)

interactive REPL (read–eval–print loop) for shell piping

  • 7.8k stars https://github.com/akavel/up

  • interactive piping

  • instant live preview

  • category: search, file manipulation, interactive

  • Demo: images/up-demo.gif

--

lolcat

Rainbows and unicorns

--

ttyd

            _ ._  _ , _ ._
          (_ ' ( `  )_  .__)
        ( (  (    )   `)  ) _)
       (__ (_   (_ . _) _) ,__)
           `~~`\ ' . /`~~`
           ,::: ;   ; :::,
          ':::::::::::::::'
 ______________/_ __ \_____________
|                                  |
|               ttyd               |
| share your terminal over the web |
|__________________________________|
  • category: network, dangerous

--

sl

typo sl (instead of ls) -> show steam locomotive

--

patat

  • 1.9k stars https://github.com/jaspervdj/patat

  • nerdy slides in your shell

  • runs in a terminal (similar to revealJs for the browser)

  • Pandoc syntax (f. ex. markdown)

  • syntax highlighting

let foo = "bar";
  • next slide: experimental image support in some terminals (same as for ranger)

    • iterm2, urxvt, kitty
  • category: presentation, slides, unix porn

--

ls on steroids

ls problem: sort by name and time at the same time...

Use colors!

Required: font providing all symbols

--

ncdu


Making Connections

the serial way

--

terminal

$ picocom -b 115200 /dev/ttyUSB0
$ screen /dev/ttyUSB0 115200
$ minicom -s -D /dev/ttyUSB0

More serial p0rn

--

grafical

  • cutecom
  • moserial
  • PuTTY

--

Windows


monitoring

  • htop
  • apachetop
  • ngxtop
  • mtp
  • pg_top
  • powertop
  • iotop
  • iftop
  • nethogs

Some more tools


Usefull online resources


Bonus: CLI murder mystery