cliday

  • About

2023-03-03

March 3, 2023

CLI Tools

  1. sampler: Tool for shell commands execution, visualization and alerting
  2. kubecolor: colorizes kubectl output

Interesting Links

  1. Introducing the Determinate Nix Installer
  2. Some notes on using nix

Tip of the Week

Formatting text:

# download three paragraphs of lorem ipsum:
% curl -s -X POST https://lipsum.com/feed/json -d "amount=3" -d "what=paras" -d "start=true" \
  | jq -r '.feed.lipsum' > /tmp/lorem.txt

# get a line count to confirm:
% wc -l /tmp/lorem.txt
3 /tmp/lorem.txt

# split the lines at 80 characters:
% fmt -w 80 /tmp/lorem.txt > /tmp/ipsum.txt

# observe `fmt` has split the paragraphs into lines:
% wc -l /tmp/ipsum.txt
25 /tmp/ipsum.txt
Continue reading

2023-02-24

February 24, 2023

CLI Tools

  1. fname: Generate random, human-friendly names
  2. python-easter-eggs: Curated list of all the easter eggs and hidden jokes in Python

Interesting Links

  1. Why GNU grep is fast
  2. Why ripgrep is faster

Tip of the Week

Using named pipes:

Processes can pipe output to other processes, e.g. ps | grep vim | wc -l, or files, e.g. pgrep vim > /tmp/vim_pids. If the processes need to communicate between users, for example, or are separated for any reason, you can use a named pipe.

# create the named pipe in an appropriate location
mkfifo /tmp/fifo

# for demonstration purposes, simple output to stdout
tail -f /tmp/fifo | tr ' ' '-'

# now begin the source process in another shell
while :; do date > /tmp/fifo; sleep 1; done

You’ll witness the input into /tmp/fifo as the output, transformed by tr. You can start and stop either process at any time, and the named pipe will remain.

Continue reading

2023-02-17

February 17, 2023

CLI Tools

  1. f3: Fight Flash Fraud
  2. vite: Next generation frontend tooling

Interesting Links

  1. Homebrew 4.0
  2. Mainframes are still a big thing
  3. Docker Compose: What’s New, What’s Changing, What’s Next

Tip of the Week

Using the GitHub CLI tool, gh, you can create and edit gists. However, to update a gist, you are required to open the file in your set editor. But we can get around this by using the VISUAL environment variable, and the tee program.

Part 1: EDITOR and VISUAL

In historical content, EDITOR would be a lightweight editor (e.g. ed) and VISUAL would be a full-fledged editor (e.g. vi). Nowadays, you can set them both to the same (e.g. vim, emacs), and you may even opt to set VISUAL to a GUI app (e.g. code for VSCode). The shell will open the appropriate program when applicable. Side note: this is similar for the PAGER variable as well, e.g. set it to bat instead of less.

Part 2: Piping with tee

The tee programs lets us split output, to stdout but also to a file. Some examples:

% date >&1  # a verbose way to show redirection to stdout
% date >&2  # redirection to stderr
% date > /tmp/date  # output to a file
% date >> /tmp/date  # append output to a file

% date | tee /tmp/date  # output to stdout _and_ a file
% date | tee -a /tmp/date  # stdout and append to a file

# pipe to stdout but also pipe to additional commands
% date +%F_%T | tee /dev/tty | tr -d ":-" | tr "_" "-"
2023-02-16_21:18:58
20230216-211858

Part 3: Putting it Together

Since gh supports VISUAL, we set it to tee so that reading in a file pipes the file contents into gh without ever opening an editor. The final > /dev/null sinkholes the file contents since we don’t need to actually see it in stdout.

VISUAL=tee gh gist edit GIST < /path/to/file > /dev/null
Continue reading

2023-02-10

February 10, 2023

CLI Tools

  1. helix: A post-modern modal text editor
  2. YouPlot: A command line tool that draw plots on the terminal

Interesting Links

  1. Why does 0.1 + 0.2 = 0.30000000000000004?
  2. The Rust Implementation Of GNU Coreutils Is Becoming Remarkably Robust
  3. What is a kubeconfig file?
  4. Why We Need Open Source Mentorship Programs at the Linux Foundation
  5. Using a 1930 Teletype as a Linux Terminal

Tip of the Week

Using the watch command:

# the most basic usage:
watch kubectl get pods -n NAMESPACE

# increase the interval:
watch -n 5 kubectl get pods -n NAMESPACE

# highlight differences between runs:
watch -d kubectl get pods -n NAMESPACE

# highlight differences from initial run:
watch -d=permanent kubectl get pods -n NAMESPACE

# kubectl has a builtin watch option:
kubectl get pods -n NAMESPACE -w
Continue reading

2023-02-03

February 3, 2023

CLI Tools

  1. fzf-marks: Plugin to manage bookmarks in bash and zsh
  2. yt-dlp: A youtube-dl fork with additional features and fixes

Interesting Links

  1. 14 Rust Tools for Linux Terminal Dwellers
  2. 5 great Perl scripts to keep in your sysadmin toolbox
  3. Open source’s impact on the world’s 100 million developers

Tip of the Week

When you have a process that is stuck or won’t respond, a good rule of thumb for escalating kills:

  1. kill -15 (TERM)
  2. kill -2 (INT)
  3. kill -9 (KILL)

The first two options give the misbehaving program a chance to quit gracefully and cleanup after itself. A -9 may leave artifacts behind (lock files, temp files, etc).

You can list all of the signals with kill -l. A function to show the signals and their number:

while read -r sig; do
  printf "%s %s\n" "$(kill -l $sig)" "$sig"
done <<< $(kill -l | tr ' ' '\n') | column

Bonus:

  • Find a process PID with pgrep <process>
  • To kill all processes that match a name: pkill -<num> <process>
Continue reading
Prev Next

Powered by Jekyll with Type Theme