cliday

  • About

2022-10-28

October 28, 2022

CLI Tools

  1. stegosaurust: Steganography tool, written in rust
  2. ugrep: ultra fast grep with interactive TUI, fuzzy search, boolean queries, hexdumps and more

Articles of Note

  • Whipping up a new Shell – Lash#Cat9
  • Command Line Interface Guidelines
  • Turn around your Git mistakes in 17 ways
  • Python team wraps version 3.11.0

Tip of the Week

The many ways of dealing with file compression:

A mnemonic for tar -xzvf file.tar.gz… e[x]tract [z]e [v]arious [f]iles

  • Can’t remember the tools for every compression algorithm? Try extract!
  • Or (a shameless plug) my own fork with added functionality!
  • Here’s a function to gzip a folder: tardir () { tar -czf "${1%/}".tar.gz "$1"; }; usage: tardir <FOLDER_NAME>
  • A oneliner to download and extract single-file zip archives: curl -sN https://.../example.zip | funzip - > ~/extracted-file

Bonus tip! Can’t transfer files (binary, zip, etc.), but only text? Use base64:

# convert to base64:
base64 -w0 /path/to/file | pbcopy  # or `xclip`, `xsel` for Linux
# transfer the text using your chosen method, the recipient should paste the plaintext in a file:
base64 -d /path/to/encoded/file > /path/to/decoded/file
Continue reading

2022-10-21

October 21, 2022

  1. nb: CLI and local web plain text note‑taking, bookmarking, and archiving
  2. 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 input
  • stdout: standard output
  • stderr: 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
Continue reading

2022-10-14

October 14, 2022

  1. difftastic: A structural diff that understands syntax
  2. coreutils: Cross-platform Rust rewrite of the GNU coreutils

Article of the week: How old various Unix signals are

The low numbered signals are the same as they are today, which at least suggests that they date back pretty far. And apart from signal 9 (SIGKILL), signals from 4 (SIGINS, illegal instruction) through 12 (SIGSYS, bad argument to system call) all seem aimed at telling you about specific internal program issues instead of being something that you would actively send.

Tip of the week: Searching for files on your system

# The `find` command is the default go-to included in Unix systems:
% touch file{1..5} && mkdir dir{6..9} && mkdir -p dir10/folder{1..5}

% find . -type f
./file3
./file4
./file5
./file2
./file1

% find . -type d
.
./dir10
./dir10/folder5
./dir10/folder2
./dir10/folder3
./dir10/folder4
./dir10/folder1
./dir6
./dir8
./dir9
./dir7

# Restict searching depth with -mindepth and -maxdepth:
% find . -mindepth 1 -maxdepth 1 -type d
./dir10
./dir6
./dir8
./dir9
./dir7

# Perform operations on the results:
% brew info coreutils --json > coreutils.json && brew info git --json > git.json
% find . -type f -name '*.json' -exec jq '.[]|.desc' {} \;
"GNU File, Shell, and Text utilities"
"Distributed revision control system"

# Delete matching results:
% find . -type f -name '*.json' -delete

Other search tools include:

  • mdfind for macOS (Spotlight CLI)
  • locate for Linux
  • fd a simple, fast and user-friendly alternative to find
Continue reading

2022-10-07

October 7, 2022

  1. pdfgrep: A tool to search text in PDF files
  2. pz: Handle day to day CLI operation via Python instead of regular Bash programs

Article of the week: Why Didn’t BSD Beat Out GNU and Linux?

Of course, BSD hardly disappeared entirely once Linux had become popular by the mid-1990s. On the contrary, a variety of operating systems based on Net 2, including NetBSD, OpenBSD and FreeBSD, remain alive and well today, with small but passionate communities of users.

Tip of the week: Use GNU Parallel to make jobs execute in parallel

# Examples showing how to split the command and the arguments:
% parallel echo {} ::: hello world
hello
world

% parallel echo {1} {2} ::: alpha beta ::: one two
alpha one
alpha two
beta one
beta two

# Convert an audio file simultaneously to multiple formats:
parallel ffmpeg ~/Audio/file.flac ~/Audio/file.{} ::: ogg m4a opus

# Simultaneously convert multiple tab separated files to csv files:
parallel "tr '\t' ',' < {} > {.}.csv" ::: *.tsv

# Create individual directory archives simultaneously:
% ls
dir1 dir2 dir3
% find . -maxdepth 1 -mindepth 1 -type d | parallel "tar -czf {.}.tar.gz {}"
% ls
dir1 dir1.tar.gz dir2 dir2.tar.gz dir3 dir3.tar.gz
Continue reading

2022-09-30

September 30, 2022

  1. nnn: The unorthodox terminal file manager
  2. jqp: A TUI playground to experiment with jq

Article of the week: It’s Past Time To Stop Using egrep & fgrep Commands

The egrep and fgrep commands have been deprecated since 2007. Beginning with GNU Grep 3.8 today, calling these commands will now issue a warning to the user that instead they should use grep -E and grep -F, respectively.

Tip of the week: Using brace expansion:

# Create some files
% for num in {1..4}; do echo "file no. ${num}" > "/tmp/file${num}"; done

# Select files to print
% cat /tmp/file{1,3}
file no. 1
file no. 3

# Select a range of files to print:
% cat /tmp/file{2..4}
file no. 2
file no. 3
file no. 4

# Make a copy of a file with a new extension:
% cp /tmp/file1{,.txt}
% ls -1 /tmp/
file1
file1.txt
file2
file3
file4

# Create multiple directories
% mkdir -p /tmp/{alpha,beta}/{one,two,three}
% tree -dL 2 /tmp
/tmp
├── alpha
│   ├── one
│   ├── three
│   └── two
└── beta
    ├── one
    ├── three
    └── two
Continue reading
Prev Next

Powered by Jekyll with Type Theme