Category Archives: Cheat Sheet

tar

Backup

See Ubuntu Help for details.

# Full root file system backup
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /

# Backup remote file system (SSH)
ssh root@srv.local -p 22 "tar -cvpz --one-file-system /" > srv-backup.tar.gz

# Restore
tar -xvpzf /path/to/backup.tar.gz -C /media/whatever --numeric-owner

Other useful commands

# Remove compression from tar.gz
gzip -dk archive.tar.gz

# Compress directory
tar -zcvf myfolder.tar.gz myfolder

# Read gzipped log
zcat error.log.2.gz

ImageMagic

# Image from PDF
magick convert -density 300 -rotate 90 -compress lossless input.pdf[0] output.jpg

# Icon from multiple images
magick convert image1.png image2.png image3.png favicon.ico

# Create favicon.ico with multiple sizes
magick convert favicon.png -define icon:auto-resize=96,64,48,32,16 favicon.ico

# Convert multiple images to jpeg with reduces size
magick mogrify -path out -format jpg -quality 80 -resize "1200x1200>" *.heic

postfix

# Show current mail queue
mailq

# Send messages in queue
postqueue -f

# Delete message from queue
postsuper -d MSGID

# Print message from queue
postcat -q MSGID

# Show mail statistics
cat /var/log/mail.log | pflogsumm

# Rebuild aliases
newaliases

journalctl

# Follow postfix mail log with 40 records loaded on start
journalctl -f -u postfix@-.service -n 40

# Get one day old records
journalctl -u postfix@-.service --since "1 days ago"

# Get first 100 records since
journalctl --since "2026-03-27 07:00:00" --no-pager | head -100

du

# Find files / directories bigger than 1GB
du -a --threshold=1G ./

# Top 20 directories by size
du -a / --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/lost+found | sort -n -r | head -n 20

# Get directory size recursively
du -hs ./

patch

# Create patch for file
diff -Naur original_file modified_file > changes.patch

# Test
patch --dry-run file_to_be_patched changes.patch

curl

# Headers only using GET
curl -s -D - -o /dev/null --url https://www.romanstefko.com/

# HEAD request
curl -I https://www.romanstefko.com/

# Test with local IP address
curl --resolve 'www.romanstefko.com:443:192.168.1.10' -s -D - -o /dev/null --url https://www.romanstefko.com/

# HTTP Proxy
curl -x http://proxy:3128 https://www.romanstefko.com

mysql

Backup

mysqldump -u root dbname > backup.sql

Restore

mysql -u root dbname < backup.sql

Commands

# Create database
CREATE DATABASE dbname;

# Create user
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbname.* TO 'user'@'localhost';