Linux

25 Mar 2025

Set Linux XDG Default App To A Flatpak

The one where we set the default system web browser to LibreWolf installed as a Flatpak

5 Sep 2024

"teethis" script is one of the most useful tools I've created

tee is a GNU tool to piggy back stout off of a pipe. The following example shows the basic pattern for using it, where the stout is printed to the terminal and written to a log file.

1
mycommand | tee mycommand.log

“teethis” script #

I frequently want to run shell scripts where I can see both the stdout and stderr immediately while preserving the output to refer to later. While the tee command to do this is relatively simple, it can be a pain to type over and over again, so I created the following teethis script.

27 Aug 2024

`apropos` is an overlooked Linux command

Search for Linux command that does what you need #

Sometimes the challenge of using the Linux command line is knowing what commands you need to do certain things. The apropos command lets you search the available commands by matching key words.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
❯ apropos csv
# bench_wcsv (3tcl)    - bench::out::csv - Formatting benchmark results as CSV
# csv (3tcl)           - Procedures to handle CSV data.
# csv2rec (1)          - csv to rec converter
# rec2csv (1)          - rec to csv converter


❯ apropos environment 
# 0desktop (1)         - add programs to the desktop environment
# 30-systemd-environment-d-generator (8) - Load variables specified by environment.d
# byobu-janitor (1)    - script for cleaning and upgrading environment after upgrades
# byobu-reconnect-sockets (1) - Sourcable script that updates GPG_AGENT_INFO and DBUS_SESSION_BUS_ADDRESS in the environment
# check-language-support (1) - returns the list of missing packages in order to provide a complete language environment
# clearenv (3)         - clear the environment
# dbus-update-activation-environment (1) - update environment used for D-Bus session services
# Dpkg::Build::Env (3perl) - track build environment
# env (1)              - run a program in a modified environment
# environ (7)          - user environment
# pam_env.conf (5)     - the environment variables config files
# ...

The command checks all of the installed man pages and package descriptions, however there are circumstances where this could leave out some relevant commands.

27 Nov 2023

Manually customize bash terminal prompt look

The prompt text that bash interprets and uses is set with the PS1 environment variable and is usually specified in ~/.bashrc. I have been manually tweaking my bash prompt look and feel to make some of my work project use-case tasks easier. The combination of default style changes, and specific prompt elements added for active environment or sourced environments should make terminal-based project management a little easier.

A little searching allowed me to discover this website that allows you to interactively customize the prompt contents and style with common components. https://bash-prompt-generator.org/

3 Nov 2023

Notifications in GNU/Linux

Installation #

1
2
notify-send
# Command 'notify-send' not found, but can be installed with:

Installation with apt #

1
2
# debian/ubuntu
sudo apt install libnotify-bin

Installation with dnf #

1
2
# redhat/fedora
sudo dnf install libnotify

Usage #

1
2
notify-send "this is the summary"
notify-send "this is the summary" "this is the body of the notification"

Send to remote machine over SSH #

1
ssh user@host 'DISPLAY=:0 notify-send "TEST MESSAGE."'

Styling with HTML #

HTML tags are supported for styling the notification messages, even including images, although the result is not styled in the case of notifications in the rofication setup used by default in the i3wm-based regolith-desktop DE.

29 Sep 2023

Who knew you can make an animated GIF with *convert*

Another thing that comes up infrequently so it is hard to remember! This method of creating an animation from a set of individual images as frames is one of the easiest I have ever seen. (Get out of here FFMPEG!)

ImageMagick’s convert animation example command #

1
convert -delay {centiseconds} -loop {loop-n-times} *.png output.gif

Here is an output made with convert from .png frames using a 25 centisecond frame advancement time.

3 Apr 2023

MNT Pocket Reform

The Pocket Reform is a smaller verison of the existing MNT Reform that is being crowd-funded and seems like exactly the type of product I have been looking for. The price is steep though, compared to the cost of DIY-ing it…

MNT Pocket Reform is an extremely compact, fully featured mini laptop that is modular, upgradable, recyclable, and reusable. Being fully open source hardware and software, it exemplifies MNT’s principles while providing abundant connectivity and a pleasant typing experience thanks to a comfortable, ortholinear mechanical keyboard and a micro-optical trackball. Pocket Reform features up-to-date Wi-Fi, Bluetooth and support for cellular modems, so you can go online anywhere.

3 Apr 2023

Reproducible Scientific Python Using Containers

Use Microsoft’s VSCode editor (code), Docker Containers, and other open-source tools for scientific Python software collaboration, development, and use on Linux and Windows. Securely connect offices, remote workers, storage resources, compute resources, and the cloud with Tailscale as a replacement for traditional VPN.

System Packages #

VSCode Editor #

Download Visual Studio Code from Microsoft.

For a Debian-based GNU/Linux distribution like Ubuntu or Pop OS, the .deb can be installed with sudo dpkg -i code_$version_amd64.deb.

30 Mar 2023

Installing Messenger For Multi-node Task-Spooler

Messenger Server #

On a base apt-based distro install the Task-Spooler Messenger Server:

1
2
3
4
5
sudo apt install -y libboost-dev libboost-system-dev libboost-thread-dev libboost-filesystem-dev

pushd messenger/messenger-server
sudo ./install
popd

Configure the messenger-server ms_server by creating ~/.hosts_ports with a port for listening to client messages.

1
echo "xxx $THISHOSTPORT" >> ~/.hosts_ports

Start the server with the command ms_server.

27 Mar 2023

Trivy

The many layers of software dependencies within containers can add extra security considerations. Luckily there are a number of tools like Trivy and Docker scan to scan Docker images for vulnerabilities.

[Trivy is a] Scanner for vulnerabilities in container images, file systems, and Git repositories, as well as for configuration issues and hard-coded secrets

Trivy can be installed with the following commands on Debian-based Linux distros, including WSL environments.

15 Dec 2022

`diff` Also Compares Directories

Short post so that I can remember this everytime I need to do something similar!

Using diff on more than individual files #

The quick and dirty explaination is that the GNU/Linux diff command has an -r flag to recursively compare two folders. The command help indicates that it is shorthand for the full --recursive flag, which might be easier to remember.

1
2
3
4
5
diff --help

# ...
  -r, --recursive                 recursively compare any subdirectories found
# ...

Example #

In the following example, “Only in” shows that particular files are only found in one of the folders. By default, matching files are not shown. If a file can be found in both folders and the two versions differ, the normal diff output is provided along with the modified times. All together these details provide a good summary of what a user might want to know when comparing two directories.

7 Dec 2022

Home Assistant (HA) Smart Home

Hardware Setup #

  • 4x Old Dell Optiplex 755 (only one machine necessary)
  • Wired ethernet switch to home wireless router and WAN
  • SONOFF Zigbee USB Dongle (this one) on one of the machines (only necessary to interact with Zigbee devices)

System Setup #

Each machine has the following:

  • Ubuntu Linux 20.04
  • Docker (with Swarm Cluster, Docker and Swarm not necessary for HA)
  • GlusterFS shared disk across the cluster, not necessary for HA

Home Assistant Docker Setup #

Start from Linux on command line as swarm service (from the machine that has the USB dongle if necessary):

18 Sep 2022

Cyber Deck Design Inspiration

It looks like a major design decision surrounds the physical size of the keyboard…

Is thumb-typing sufficient if all the required keys are present, or are there touch-typeable keyboards available at a reasonably small size?

17 Sep 2022

Cyber Deck Project

While traveling recently, I became frustrated with my aging 11" Thinkpad and the limitations of iPhones or tablets, so I have started looking into sourcing a customized computer for use on the go.

I’d like it to have the following items for practicality:

  1. Full GNU/Linux OS
  2. USB chargeable with battery
  3. Medium book sized (like iPad Mini or A5 Paper) dimensions assuming a couple inches thick
  4. Large internal storage
  5. Full keyboard (especially things like system key, tab, delete, home/end, etc.)–size is negotiable though
  6. Mouse or touchscreen
  7. Yoga-style hinges for laptop, lay-flat, and tablet form factors

Most off-the-shelf options are too expensive for what they offered (GPD), out-of-date (original netbooks), or poorly reviewed. Modifying a second-hand tablet or netbook, or building something from scratch seems like a reasonable option to get everything I want.

24 Mar 2022

Bad Hacks to Find Linux Drive Device from UUID

On linux, you can’t count on the devices listed under /dev/sd* or /dev/xvd*, to have the same names or order. With the UUID (which is how /etc/fstab usually specifies how to mount the root system device), the /dev device name can be determined using the blkid command and some hacky bash.

1
2
# For a system that uses /dev/sda, etc. use 0:8 string slice for blkid
MYDEVICE=$(blkid | grep ${MYUUID}) ; echo ${MYDEVICE:0:8}  # /dev/sdc

However, you might need to do something like start a Docker container with your main system device connected using docker run --device=..., and so the following also works in this specific case looking for the device mounted at the local machine’s /.

17 Feb 2021

Dependency Hell

I started my Python package management journey years ago using pip, then more recently I embraced Anaconda and conda more fully (particularly with the “conda-forge” repository) to resolve complex dependencies along with system/binary dependencies. Recently, when attempting to update our team’s standard Python docker image with the latest versions of the packages we use, and include some new ones, it appears that relying on conda and conda-forge is untenable: I have been unable to resolve the appropriate set of versions for the scientific Python packages our team require for our work. I have moved back to pip for packages which are not provided in the default Anaconda repository. pip has and continues to make a number of improvements, and had no problem providing our extra dependencies.

10 Feb 2021

Overlooked Tools: 'watch'

There many GNU/Linux command line tools that provide continuously updated statistics or information like iotop, nload, and top. However, it is often necessary to see the output of another simple command or complex chain of tools, updated in real-time.

watch is a Linux command that does just that, and by doing so, is incredibly useful for continuously monitoring the output of any Linux terminal command. Usage of the watch command is incredibly simple, as the following example monitoring the currently running tsp task in the task-spooler queue demonstrates.

17 Nov 2020

Overlooked Tools: task-spooler

Sometimes sophisticated job queue and cluster systems are overkill on office or individual PCs, especially for long lists of batch processing jobs that use comparatively few resources.

Use task-spooler to queue commands on Linux and control the number of simultaneous jobs for an easy way to parallelize a list of batch jobs! This tool is a great complement to some other command line workhorses like at and batch.

Task-spooler is not usually installed by default on Linux systems. It can be built by scratch after getting the source from https://vicerveza.homeunix.net/~viric/soft/ts/ or on Ubuntu (maybe other Debian based OS’s) you can use apt:

16 Nov 2020

Overlooked Tools: xclip

If you have ever had a need to move the output of a Linux console command to your clipboard, xclip is the solution!

To copy a file’s contents to the standard “ctl+c/v” clipboard buffer issue you can following this command:

1
xclip -sel clip your-file-path

The most useful feature is reading from a stdin pipe:

1
head my-file-path | xclip -sel clip

…and then your ready to paste into an email or Slack chat.

2 Sep 2019

Shortcut to Website in Ubuntu 18.04 Dock

Create and populate the following file to add a dock shortcut to a website in Ubuntu using Ars Technica as an example. This will also enable the shortcut in the Gnome Shell search.

~/.local/share/applications/MyWebsite.desktop:

[Desktop Entry]
Comment=Ars Technica
Terminal=false
Name=Ars Technica
Exec=firefox https://arstechnica.com/
Type=Application
Icon=applications-internet
NoDisplay=false

To use Google Chrome instead, replace firefox with google-chrome if it is installed.

[Desktop Entry]
Comment=Ars Technica
Terminal=false
Name=Ars Technica
Exec=google-chrome https://arstechnica.com/
Type=Application
Icon=applications-internet
NoDisplay=false

23 Aug 2018

Reproducing Conda Environments

This short summary is based on the Anaconda blog post here https://www.anaconda.com/moving-conda-environments/. The original blog post is a great high-level summary for the various methods in conda for reproducing environments.

  • OS and platform specific (pulls from repos)

    # On source environment:
    conda list --explicit > spec-list.txt
    
    # New conda environment:
    conda create --name new_env_name --file spec-list.txt
    
  • Different platforms and OS (pulls from repos, also includes pip installed packages)

    # On source environment:
    conda env export > env.yml
    
    # New conda environment:
    conda env create -f env.yml
    
  • Platform and OS specific, no internet on target

17 Mar 2018

Installing NetCDF Python Packages

I was trying to remember how I have installed netCDF4 and related libraries for Python, and what I need to do differently for Windows systems vs. the Linux systems I usually use.

On Linux, sometimes I use the system netCDF C libaries, but often I compile and install specific versions of HDF5 and netCDF4 from scratch. Here is how I have built netCDF for various Docker container images.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Build HDF5
cd hdf5-x.y.x
./configure --prefix=/usr/local --enable-shared --enable-hl
make
make install
cd ..

# Built NetCDF4
cd netcdf-x.y.z
LDFLAGS=-L/usr/local/lib
CPPFLAGS=-I/usr/local/include
./configure --enable-netcdf-4 --enable-dap --enable-shared --prefix=/usr/local --disable-doxygen
make
make install
cd ..

# NetCDF4 Fortran
cd netcdf-fortran-x.y.z
./configure --enable-shared --prefix=/usr/local
make
make install
cd ..

netcdf4-python #

I typically try to use pip to install Python libraries if I can. Use pip if you need to, but I am using conda and conda-forge as much as possible now, in fact by using conda, the above compilation steps are usually not necessary as far as I know. See below.

1 Jan 0001

Overlooked Tools: 'at'

If you find you are using commands like sleep to run a one-off task at a specific time, then meet the GNU at command.

at will allow you to specify a time to run a specific command, and accepts a wide range of different formats including “now + 4 hours”, “noon”, and “next tuesday”. The command will read commands from stdin or using the -f to specifiy a file to be executed using the default /bin/sh.