Usefull Linux one-liners

January 29, 2022

This post will contain usefull one-liners. This might change from time to time.

Ubuntu recompile dkms modules

dkms status | sed s/,//g | awk '{print "-m",$1,"-v",$2}' | while read line; do ls /var/lib/initramfs-tools | xargs -n 1 dkms install $line -k; done

Remove old kernels

sudo dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge

Backup image to remote over ssh

dd if=/dev/sdX bs=64k status=progress | gzip -1 - | ssh user@my.ip.address dd of=/home/username/filename.img.gz

Backup remote disk to local over ssh

ssh user@my.ip.address "sudo -S dd if=/dev/sdX bs=64k status=progress | gzip -1 -" | dd of=filename.img.gz bs=64k

Keep only last 5 snapshots FreeBSD

zfs list -H -t snapshot -o name -S creation tank | tail -5 | xargs -n 1 zfs destroy

Keep only last 5 snapshots Linux

zfs list -H -t snapshot -o name -S creation -r bpool | tail -5 | xargs -n 1 zfs destroy

Backup local zfs snapshot to remote nas

zfs send -Rv tank/bhyve/anydataset@2023012301 | ssh remotesys zfs recv -vF backup_tank/archive/anydataset