APT

APT is the package manager for Debian and the likes. I use it on Ubuntu, so here’s some useful commands I occasionally need.

Update and Upgrade

sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y

more convenient as an alias in .bashrc including snaps:

alias up='sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo snap refresh'

Mark package as automatically installed

apt-mark auto <package>

This allows the package to be cleaned up by apt autoremove, don’t use it on critical packages like ubuntu-desktop. See the manpages for more options.

Show all manually installed packages

apt-mark showmanual

For moving to a new system or purging single-use programs. via Ask Ubuntu

Reverse dependencies

apt-cache rdepends <package>

Do you really need that library anymore? This command shows you which packages depend on it, so you can decide whether to keep it. via Ask Ubuntu

PostgreSQL

Shell

sudo -u postgres psql

Check Version

Server version:

pg_config --version

Client version:

psql --version

via Stack Overflow

Upgrade PostgreSQL

OLD=16
NEW=$((OLD+1))
sudo apt install -y postgresql-$NEW
sudo systemctl stop postgresql$OLD
sudo pg_upgradecluster $OLD main

If the new cluster works: sudo pg_dropcluster $OLD main

TempFS

lost on shutdown, will swap to disk if needed

sudo mkdir /mnt/tmpfs
sudo mount -t tmpfs -o size=8G tmpfs /mnt/tmpfs

list all filesystems: df -h

Play mp3 in a virtual microphone

temp=$(mktemp -d)
pactl load-module module-pipe-source source_name=virtmic file=$temp/virtmic format=s16le rate=44000 channels=1
pactl set-default-source virtmic
ffmpeg -re -i sample.mp3 -f s16le -ar 44000 -ac 1 - > $temp/virtmic

pactl unload-module module-pipe-source