Posts Tagged: CLI

htop

htop

htop is an interactive text-mode system-monitor process viewer for GNU/Linux. It aims to be a better ‘top’. It shows a frequently updated list of the processes running on a computer, normally ordered by the amount of CPU usage. Unlike top, htop provides a full list of processes running, instead of the top resource-consuming processes. htop uses color and gives visual information about processor, swap and memory status.

Continue reading

CLI Database optimization

CLI Database optimization

MariaDB & MySQL:

sudo apt install default-mysql-client   # or: mariadb-client
mysqlcheck -h yourdatabasehost -u root -p --auto-repair --check --all-databases
mysqlcheck -h yourdatabasehost -u root -p --auto-repair --optimize --all-databases
# Note: MariaDB 11+ also provides mariadb-check; --optimize rebuilds InnoDB tables, so schedule on busy databases carefully.

PostgreSQL:

vacuumdb -afvz -h yourdatabasehost -U postgres
reindexdb -a -h yourdatabasehost -U postgres

Updated (November 4, 2021): Docker example:

docker exec -it postgres-server vacuumdb -afvz -U postgres

GNU/Linux CLI image optimizer

GNU/Linux CLI image optimizer

There are major speed benefits to image optimization using optipng for PNGs, gifsicle for GIFs, and jpegoptim for JPEGs. Optimized graphics transfer faster and improve perceived load times. Below, optipng and gifsicle optimize PNG/GIF files losslessly, whereas adding --max=85 or ImageMagick -quality 80 applies bounded lossy compression to JPEGs (omit --max=85 if you only want lossless metadata stripping).

Ubuntu / Debian:

sudo apt update && sudo apt install optipng gifsicle jpegoptim imagemagick

Run these commands inside the target directory as the user who owns those images (note the quoted '*.ext' globs so the shell never expands them prematurely):

find . -type f -iname '*.png' -exec optipng -o7 --strip all {} \;
find . -type f -iname '*.gif' -exec gifsicle -O2 -b {} \;
# Strictly lossless JPEG strip:
find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec jpegoptim --strip-all {} \;
# Optional bounded lossy + progressive pass for web assets:
find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec jpegoptim --strip-all --max=85 {} \;
find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec convert -interlace line -quality 80 {} {} \;

For WordPress automation, you can install EWWW Image Optimizer or convert assets to WebP/AVIF.