Search This Blog

Sunday, November 29, 2026

print filenames containing a string

I used to use a combination of grep and awk commands to produce the list of files with a given string. For example, to get all the files in the "/etc" with a string "crux" I would run:

grep -sc crux /etc/**/*(.) | awk -F: '{if ($2!=0){print $1}}'

The key is to use the -c option, to count the number of lines with the string. The -s suppresses error messages. Then the output is passed to awk, which splits the line on "< b>:" and prints the first field, if the second one does not equal to 0. In the above example, I used the zsh globbing /etc/**/*(.) for recurse search of all files in the /etc directory.

But there is a simpler way.

grep -sl crux /etc/**/*(.)

The -l grep option suppresses normal output and prints only the file name containing the searched string.

Sunday, October 25, 2026

Check used ports with lsof

The lsof standing for "list open files", yet its definition of a file is very broad: not only files and directories, but also block and character devices or streams and libraries, as well as sockets, both UNIX and network ones. Therefore, it can be use for some networking investigations. For example I use it to started qucikly find occupided ports. 

On Linux I used to use netstat. Once I needed to do it on MacOS. GNU and BSD netstat differs, and it includes diffrent options and syntax [2,3]. Additionally, in Linux the net-tools package providing netstat is depricated, and it's replaced with ss. Side note ss works similar to the BSD flavour of netstat: directly communicating with kernel, rather than relaying on the /proc filesystem. Luckly, I remembered that lsof can do some network scanning, and should work identical on both systems. 

When using lsof for a network investigation the key is the option -i, which allows intorigation of network addresses [4]. There are extra options to refine the filter. For example, to get a list of TCP ports run: 

lsof -P -n -i TCP -s TCP:LISTEN
  • -P -- (ports) shows port numbers (do not translate to port names)
  • -n -- (numbers) shows IP addresses (do not translate to hostnames)
  • -i -- (internet) shows internet file; can be further narrowed by extra terms
  • TCP -- (protocol) narrows type of internet files to show to the given protocol
  • -s -- (state) shows only files defined by a protocol:state pair which follows
  • TCP:LISTEN (protocol:state) -- the pair narrowing output only to TCP connection in the LISTEN state

For more examples of lsof usage check [1]. Just note that some of the commands presented ther might lack -s for the state definition.

Links

  1. www.linuxnetwork.net/blog/lsof-i-reveal-information-about-your-network-sockets/#why-lsof--i
  2. linux.die.net/man/8/netstat
  3. man.freebsd.org/cgi/man.cgi?netstat
  4. linux.die.net/man/8/lsof

Saturday, September 19, 2026

Start an AppImage

When there is no Crux ports, and the application is complex to build I like to use AppImages. To make the the use of them easier I make these two things:

  • download all of them to selected place (in my case '${HOME}/bin/AppImage')
  • creates a launcher script in my home bin directory.

The scripts are all based on the following template:

#!/bin/bash

name={THE_NAME_OF_THE_APP_HERE}

appPath=${HOME}/bin/AppImage
cd $appPath
binary=$(ls -r1t ${name}*|tail -1)
./$binary

The only thing I need to adjust in there is the name of the application, as it is used i the image filename. The scripts scans the content of the selected folder for all of files containing the define string/name. From them selects the latest (combination of ls and tail) and start is.

To avoid defining the name inside of the I could use the filename of the script as the pattern 'name=$(basenmae ${0})'. However, the name has to the launcher would need to match exactly the name in app image including capitalization.

Final step is to crate the the desktop entry. That's an example for the Inkscape (the file is located in '${HOME}/.local/share/applications/appimage-inkscape.desktop'). I add the appimage prefix to a filename to easily find my appimage applications among other entries.

[Desktop Entry]
Name=Inkscape
GenericName=Vector graphic editor
Exec=inkscape
Icon=inkscape
Comment=Application for drawing
Type=Application
Categories=Graphics;
Hidden=false
NoDisplay=false
Terminal=false
StartupNotify=false
StartupWMClass=Inkscape
DBusActivatable=false

Of courese an image file (e.g. png or svg) with the right name has to be stored in the on standard directories (e.g '${HOME}/.local/share/icons/'). Worth to note, that I have a problem with the "RunEverything" (Enligthenment application launcher) entries, if the Exec is just a script name, rather than the whole path.

Saturday, August 29, 2026

A few not so random Linux links

First Vim and Matthieu's great introduction to search. Check his blog for more articles not only about Vim.

Staying in Vim space. Vimcasts is a series of short videos on Vim prepared by Drew.

The "Esc . Enter" (escpace, dot, enter) is a useful trick I learnt from the Charlie's blog post on SSH escape sequences. That's another good source of information on Linux CLI, e.g. how to find motherboard details from shell.

Links 

Tuesday, July 28, 2026

KeePassXC sync, Dropbox and RPi

Intro

I keep my passwords in the KeePassXC DB and use Dropbox to synchronising it between multiple computers (and phones). It has been working fine for years, until I decided to try set RPi as a desktop. Dropbox does not provide a client for Arm architecture. However, as quite often in the world of open source, there is an alternative. Rclone is a tool allowing you to manage files in over 70 cloud provider, including Dropbox.

Software is easy to install and configure. Just run rclone config and follow prompts, choose Dropbox, authenticate via browser, as documented in the Dropbox section of the project website.

Sync

For syncing one file, rarely changed, a simple script around rclone is good enough. It provides 2 functions: pull and push.

#!/bin/bash
REMOTE="dropbox:path/to"
REMOTE_PATH="${REMOTE}/YourDB.kdbx"
LOCAL_PATH="${HOME}/keepass"
LOCAL="${LOCAL_PATH}/YourDB.kdbx"

case "$1" in
  pull)
    rclone copy "${REMOTE}" "${LOCAL_PATH}"
    echo "Pulled from Dropbox"
    ;;
  push)
    rclone copy "${LOCAL}" "${REMOTE_PATH}"
    echo "Pushed to Dropbox"
    ;;
  *)
    echo "Usage: $0 pull|push"
    ;;
esac

The script assumes that the name of the remote was set to dropbox and the local copy is stored in the ~/keepass directory. Note, that for the copy source is the name of the file, but destation is the folder.

Cronjobs

To to mimize a chance of reading outdated passwords it's worth to automated the pull step. Just pull, because KeePassXC handles conflicts well at the application level (it can merge databases), but rclone itself is not conflict-aware. Automated push can overwrite changes from another machines, or copy a corrupted file.

# Automated sync every half-hour
*/30 * * * * rclone copy dropbox:path/to/YourDB.kdbx ~/keepass/ --log-file=~/.local/var/log/rclone-keepass.log --log-level ERROR
# Extra daily backup
3 3 * * * rclone copy dropbox:path/to/YourDB.kdbx ~/keepass/$(date +\%Y-\%m-\%d)/ --log-file=~/.local/var/log/rclone-keepass-backup.log --log-level ERROR

Links

Tuesday, June 30, 2026

Cruxpy as an example of the python package release process

As mentioned before, CruxPy helped me to automate the process of keeping the repository of my Crux ports rolling. It also gave me a chance to prepare a pipeline for a Python package with GitHub Action (GHA) workflows.

On every commit the GHA runs 2 jobs. First, pytest. When the tests pass, it checks the version stored in the pyproject.toml file, and compares it to the latest tag. If the version from the file is higher than the current tag, the new one is pushed. These jobs are stored in the commit.yaml file.

When there is a new tag pushed to the code, another workflow, from the release.yaml file, kicks off. It has only one job - to create a GitHub release.

The completion of the "New Release" job triggers the third workflow saved in the deploy.yaml file. It is responsible for publishing the python package to the pypi repository.

If you are just starting your adventure with GHA, you might want to check triggers to understand them better.  This pipeline uses three distinct types:

  • commit is defined as push to every branch (excluding tags)
  • release uses a push of a tag, that matches 3-number semantic version
  • deployment relays on the internal GitHub workflow dependencies.

This structure allows me to push changes directly to the main branch safely. Nothing becomes visible outside of repository until the version is bumped!

Friday, May 01, 2026

Watching GitHub PRs

In one of my previous posts I explained how to check the status of your PRs from the command line. Recently, I added one more improvement to ensure that also PRs without any reviews yet are listed with the PENDING state. This is achieved by using the fallback operator // in the jq: \(.reviews[-1].state // "PENDING") command.


gh pr list \
 --author @me \
 --json "number,title,reviews" \
| jq '.[] | "PR \(.number): \(.title) is \(.reviews[-1].state // "PENDING")"'

I also discovered (with some help from AI) how to watch the PR state live in full colour: combine the watch tool  --color option with one of 2 environment variables:


watch --color 'GH_FORCE_TTY=1 gh pr view'
watch --color 'CLICOLOR_FORCE=1 gh pr view'
  • GH_FORCE_TTY=1: is the gh specific option and forces the GitHub CLI client to behave as it is running in a terminal, even if it's not (e.g. piped or run inside watch).
  • CLICOLOR_FORCE=1: is part of the CLICOLOR standard and affects other tools as well. It forces the tool to output colours regardless whether it is running in a terminal or not. 

Links