basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Lesser-known aliases: tail -F, dmesg -T, color for ip and diff

    A second batch for ~/.bash_aliases: a log tail keeps following after rotation, wall-clock timestamps in the kernel log, color for ip and diff, top memory users, copy with progress, site certificate expiry. Append to the file from Everyday aliases: several lines rely on its alias sudo='sudo '.

    How they were picked

    Each line either exposes a lesser-known flag of a standard tool or guards against a silent failure: tail -f quietly stops showing lines after log rotation, and dmesg prints seconds since boot. For existing command names (dmesg, ip, diff), the aliases only adjust formatting, just as in Everyday aliases. Where behavior changes, they get a new name: tailf, mem, cpv.

    The file, block by block

    ~/.bash_aliases — continued
    # log that survives rotation: tailf /var/log/nginx/access.log
    alias tailf='tail -F'
    Key part

    Ubuntu’s default logrotate config (create in /etc/logrotate.conf) renames app.log to app.log.1 and creates a fresh app.log. tail -f tracks the open file descriptor — which is now app.log.1 — and goes silent while new lines go to the new file. tail -F tracks by name, notices the swap (tail: 'app.log' has appeared; following new file), and switches over. Press Ctrl+C to exit. Ubuntu doesn’t ship a tailf command, so the name is free.

    alias dmesg='dmesg -T'

    dmesg prints seconds since boot, [ 0.000000]; with -T, it shows wall-clock time, [Wed Nov 11 16:15:09 2026]. Display only. Ubuntu restricts the kernel buffer to root, so run sudo dmesg. After suspend and resume, -T timestamps can drift — man dmesg warns about this. For accurate timestamps, use journalctl -k -b.

    alias ip='ip -color=auto'
    alias diff='diff --color=auto'

    Color in terminals only: auto omits escape codes when redirecting to a file or pipe. In ip, UP is green, DOWN is red, and IPv4/IPv6 addresses use distinct colors, so a down interface jumps out at a glance. In diff, removed lines are red and added lines are green, making config edits stand out immediately.

    alias mem='ps aux --sort=-%mem | head'
    alias cpu='ps aux --sort=-%cpu | head'

    Top memory and CPU consumers: processes sorted descending, heaviest first, nine rows under the header. %CPU here is the average over a process’s lifetime; for live CPU usage, use top. Neither alias accepts arguments because of the pipe: mem 5 passes 5 to head (head: cannot open '5' for reading). For a configurable row count, write a function (Bash functions).

    alias jerr='journalctl -p err -b'

    Errors since the last boot: priority err and higher (crit, alert, emerg). Check right after a reboot alongside failed from Everyday aliases. jerr -1 shows the previous boot: the argument lands after -b. Readable by root and the adm group.

    alias cpv='rsync -ah --info=progress2'

    Copy with a single-line overall progress bar: 52.43M 100% 489.89MB/s 0:00:00 (xfr#1, to-chk=0/1). -a preserves permissions, ownership, and timestamps; -h formats sizes in K, M, G. If a copy is interrupted, rerunning skips files already copied in full. Trailing slashes on directories matter: cpv photos/ /mnt/backup/photos/ copies the contents; without the slash, it puts the photos directory itself inside.

    alias bat='batcat'
    alias fd='fdfind'

    Only if the packages are installed: sudo apt install bat fd-find. bat is cat with syntax highlighting and line numbers; fd finds files by name fast. On Ubuntu, the binaries are named batcat and fdfind because /usr/bin/fd in Debian is already taken by fdclone. The aliases restore the usual names in your shell. To make scripts see them too, symlink instead: ln -s /usr/bin/batcat ~/.local/bin/bat.

    alias watch='watch '

    Trailing space, same trick as sudo: watch ports expands the alias and refreshes every 2 s. Works only for aliases without internal quotes: watch hands the string to sh -c, stripping quotes and breaking watch dps. Flags before the alias name also prevent expansion — both cases are in “If it doesn’t work”.

    # check when a site's certificate expires: certend example.org
    certend() { echo | openssl s_client -connect "$1:443" -servername "$1" 2>/dev/null | openssl x509 -noout -enddate; }
    Key part

    Expiration date of the certificate a site is serving right now: notAfter=Dec 25 22:13:27 2026 GMT. Run after setting up HTTPS or when renewal looks stuck. -servername is required when several sites share one IP so the proxy picks the right certificate. echo | closes the connection right after the handshake; without it, s_client waits for input.

    If it doesn’t work

    watch dps prints accepts no arguments

    Cause
    watch joins words with spaces and hands the string to sh -c. Quotes inside the dps alias get stripped, so the format reaches docker in pieces.
    Fix
    Pass a command with quotes to watch wrapped in single quotes: watch 'docker ps --format "table {{.Names}}\t{{.Status}}"'.

    watch -n 5 ports prints sh: 1: ports: not found

    Cause
    The trailing space in alias watch='watch ' expands only the word immediately after watch, which here is -n.
    Fix
    Run watch ports without flags to refresh every 2 s. When passing flags, write the full command: watch -n 5 ss -tulpn.

    Installed the bat package, yet bat returns command not found

    Cause
    On Ubuntu, the package installs the binary as batcat, and fd-find installs as fdfind.
    Fix
    Use the bat and fd aliases from this file, or add symlinks in ~/.local/bin so scripts find them too.

    dmesg prints read kernel buffer failed: Operation not permitted

    Cause
    Ubuntu restricts reading the kernel ring buffer to root.
    Fix
    Run sudo dmesg — the alias expands thanks to alias sudo='sudo '. Or use journalctl -k -b, which members of adm can also read.

    cpu puts a process at the top even though it barely uses CPU right now

    Cause
    %CPU in ps is a lifetime average: total CPU time divided by elapsed time. A process that spiked for a minute an hour ago stays near the top.
    Fix
    To see current CPU load, run top — it sorts by live CPU usage by default.

    How to check

    type tailf jerr
    # tailf is aliased to `tail -F'
    # jerr is aliased to `journalctl -p err -b'
    certend example.org
    # notAfter=Dec 25 22:13:27 2026 GMT

    Verify that tail -F switches to a rotated file by simulating rotation in a second terminal:

    mkdir -p /tmp/rot && cd /tmp/rot && echo one > app.log
    tailf app.log
    # in a second terminal:
    cd /tmp/rot && mv app.log app.log.1 && echo two > app.log
    # in the first terminal:
    # tail: 'app.log' has become inaccessible: No such file or directory
    # tail: 'app.log' has appeared;  following new file
    # two