- nb: CLI and local web plain text note‑taking, bookmarking, and archiving
- bearings: A fast, clean, customisable shell prompt for zsh, bash, fish, and more…
Articles of note:
- Google shows off KataOS, a secure operating system written in Rust
- Some less popular git commands
- Google submits Go apps container project to Cloud Native Computing Foundation
- Save keystrokes with Vim abbreviations
- Ubuntu 22.10 (Kinetic Kudu) Is Now Available for Download, This Is What’s New
Tip of the week: Using shell redirection
There are three file descriptors when executing commands on the shell:
stdin
: standard inputstdout
: standard outputstderr
: standard error
# Some basic redirection
% ls -l # stdout is printed to the terminal
% ls -l > /tmp/ls-l.txt # stdout is redirected to a file
% > /tmp/ls-la.txt ls -la # stdout is redirected to a file (order doesn't matter)
% ls -M # stderr is printed to the terminal
ls: invalid option -- 'M'
Try 'ls --help' for more information.
% ls -M 2>&1 | grep 'invalid' # stderr is redirected to stdout
ls: invalid option -- 'M'
% ls -M 2> /dev/null # stderr is sent to a blackhole (i.e. ignore all errors)
# Some intermediate redirection
% for i in {1..5}; do date >> /tmp/timestamps; sleep 5; done # append output to file
% for i in {1..5}; do date | tee /tmp/timestamps; sleep 1; done # split stdout to file and terminal
% brew list --formula -1 > /tmp/brew-list # output a list of installed packages
% while read -r formula; do brew info $formula; done < /tmp/brew-list # stdin is a file
% while read -r formula; do brew info $formula; done <<< "$(brew list --formula -1)" # stdin is a command
% docker image prune -f > /dev/null 2>&1 # redirect stderr to stdout and redirect stdout to /dev/null (i.e. ignore everthing)
# Using redirection instead of pipes
% tr ' ' '\n' <<< "$(id -Gn)"
% sed 's/Fri/Friday/' < /tmp/timestamps
# Using process substitution
% diff <(sort file1) <(sort file2) # the output of a command appears as a file