Finding Files that have a Size between two Values given in Bytes

Save this as file /usr/local/bin/find-by-size and mark it executable:

#!/usr/bin/env perl

use strict;

use File::Find;

our $min = $ARGV[0];
our $max = $ARGV[1];
our $dir = $ARGV[2];

do {
    print STDERR "Usage: $0 MIN MAX DIR\n";
} unless defined $min && defined $max && defined $dir && -d $dir;

sub w {
    -f && do {
        my $bytes = -s;
        $::min <= $bytes <= $::max &&
            printf "% 10d %s\n", $bytes, $File::Find::name;

find(\&w, $dir);

Use it as follows:

$ find-by-size 10 20 /etc

Print XDG Desktop Definition for Application

For an application given by „application name“ or „executable name“, output the corresponding .desktop file, if any:

find_desktop() {
  local IFS=":"
  local xdg_data_dirs=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
  local search=$1 
  for i in $xdg_data_dirs ; do
    [ -d $a ] && for d in "$a"/*.desktop ; do
      grep -q -e "^Name=.*$search" -e "^Exec=.*$search" "$d" && {
        echo "# $d:"
        grep -Ev '^(Comment|GenericName|Keywords|Name\[)' "$d"

Try it:

find_desktop gnome-terminal

Transforming Sets of Strings to their Common Prefix Notation

Any two strings s1, s2 have a common prefix cp, which is the string of characters that s1 and s2 have in common up from the start. If s1, s2 have no such common characters, cp is the empty string. Let 1, 2 be the remainders or suffixes of s1 and s2 if cp is removed from them. Then, the common prefix notation (CPN) of s1, s2 – in short, cpn(s1,s2) – shall be:

cpn(s1,s2) := cp{1,2}

Given the definition above, for any given CPN of a set of strings s1, s2, …, sn, the CPN of the set extended by an additional string sn+1 is defined as follows:

Case 1: If the suffix of sn+1 with cp removed, n+1, has no nonempty common prefix with any of the suffixes 1, 2, …, n:

cpn(s1,s2,…,sn+1) := cp{1,2,…,n+1}

Case 2: Otherwise, since the first characters of 1, 2, …, n are distinct, there can only be one element m that has a nonempty common prefix with n+1. Given m to be that element:

cpn(s1,s2,…,sn+1) := cp{1,2,…,cpn(m,n+1),…,n}


cpn("a", "b") = "{a,b}"
cpn("aa", "ab") = "a{a,b}"
cpn("aa", "ab", "abc", "abd") = "a{a,b{c,d}}"
cpn("a", "ab", "abc") = "{a{b{c}}}"

Note 2: For the sake of reasoning, strings containing the CPN’s reserved characters {, } and , shall be considered invalid input. In a practical implementation, a syntax for „escaping“ these reserved characters should be available.

Given a set of strings, one per line, on standard input, the following Python program prints the CPN of these strings on standard output:

Try the examples:

./ << EOF
./ << EOF
./ << EOF

The following example renders the wrong output, because a trie does not actually store the common prefix (this is what a suffix tree would accomplish), it just stores different prefix paths, and a, ab and abc have no different prefix paths, it’s just a degenerate tree a → b → c:

./ << EOF

So my guess is, i must implement one of these fancy suffix tree algorithms to get it done right. 🙂

In the meantime, try this:

find /etc -type d | ./



Mein Arbeitgeber, B1 Systems GmbH hat in meinem Namen eine Patenschaft für einen afrikanischen Pinguin gesponsert. 🙂

Weiterlesen … »

Pi-KVM Hat v3

Ich freue mich, zu den Glücklichen zu gehören, die den Pi-KVM Hat v3 mit passendem Stahlgehäuse ergattert haben ( Das Warten hat sich gelohnt.

Weiterlesen … »

CentOS/8 Stream on libvirt/KVM with Kickstart and virt-install

This article describes using Kickstart to automate the CentOS installer and virt-install to automate the creation of a VM.

The following setup is assumed:

  • There is a libvirt hypervisor called virthost.
  • ssh to virthost as „root“ is possible.

Weiterlesen … »

WordPress-Plugin to Embed Gitlab Project Information

For my personal use, i wrote a small WordPress plugin that allows me to embed a link to a Gitlab repository, a list of commits and a link to the releases of that project in a WP post.

Example (linebreaks added to shortcode for readability):



Gitlab-Projekt linuxfoo-gitlabLetzte 3 Commits:2022-01-01 : f6abb63a add option author="none"2021-11-30 : 4b7b8d4a project_header formatting2021-11-29 : 95fa3719 Merge branch 'main'Neueste Release: v1.4.3

Weiterlesen … »

Interactive nftables Ruleset Editor

I wrote a simple shell tool to interactively edit the current nftables ruleset using a terminal-based text editor (respecting environment variable EDITOR and defaulting to vim).

For testing purposes, it can optionally revert the changes after a timeout specified in seconds (option --timeout SECONDS, requires systemd-run).

Weiterlesen … »