Skip to content

Instantly share code, notes, and snippets.

@dbirks
Last active March 26, 2022 17:48
Show Gist options
  • Save dbirks/0d78abbb9d242b0032266dab0d968e42 to your computer and use it in GitHub Desktop.
Save dbirks/0d78abbb9d242b0032266dab0d968e42 to your computer and use it in GitHub Desktop.
Helpful commands

Helpful commands

dpkg

Show packages put on hold

dpkg --get-selections | grep hold

Or cleaner:

apt-mark showhold

helm

Show releases in all namespaces

helm ls -A

Show all releases

This shows all releases in the monitoring namespace, even those releases normally not shown, like those that have the pending-upgrade status:

helm ls -n monitoring --all

Print the current manifests running

Print the manifests currently applied with the loki release in the monitoring namespace:

helm get -n monitoring manifest loki

ImageMagick

Resize image to maximum width

convert -resize '600' original.jpeg resized.jpeg

Resize image to maximum height

convert -resize 'x1024' original.jpeg resized.jpeg

Resize image to approximate filesize

convert original.jpeg -define jpeg:extent=150kb output.jpeg

git

Grab commit short hash

git rev-parse --short HEAD
# or
git submodule status repo-name-here | grep -Eo '[0-9a-f]{40}' | cut -c 1-7

jq

Set a value

jq '.engines.node = "12.20.0"' package.json

Reference an environment variable

export NODE_VERSION=12.20.0
jq '.engines.node = env.NODE_VERSION' package.json

ls

Handy flags

-a show all files

-h show hidden files

-l list

-r reverse order

-S sort by size

-t sort by modified date, most recent first

LVM

Extend logical volume to full size

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

MySQL

Backup database

mysqldump -u dbuser -p dbname > descriptive-name-dbname-db-2017.07.19.sql

Import database

mysql -u dbuser -p dbname < descriptive-name-dbname-db-2017.07.19.sql

Configure password-less login

mysql_config_editor set --login-path=backup --host=localhost --user=backup --password

Now you can run mysql or mysqldump like this:

mysql --login-path=backup

You can also list all of the saved login paths saved for the current logged-in user:

mysql_config_editor print --all

nix

Remove old system generations

sudo nix-env --profile /nix/var/nix/profiles/system --delete-generations 7d

Garbage collect

nix-store --gc

nmap

Scan network for partial DNS name

Scan the subnet without a complete port scan, then pipe it into grep to search for a partial name.

nmap -sn 192.168.10.0/24 | grep -i c551

qemu

qemu-system-x86_64 -cpu host -enable-kvm -m 4096 -smp 4 -drive file=~/Downloads/windows-server.vhd

Then Ctrl + Alt + G to release QEMU's hold on your mouse.

rsync

A starting point

rsync -avP source destination

-a archive mode (recursive, preserves permissions)

-v verbose

-P shows progress and keeps partially transferred files

Additional handy options

--bwlimit= bandwidth limit, in kBps

ssh

Create a ed25519 key

ssh-keygen -t ed25519

SOCKS proxy

ssh -D 12345 -p 4022 user@host.domain.com

sshfs

Mount a directory over ssh

sshfs -o allow_other david@FQDNhere:/source/path /mnt/localpath

Mount at boot

Add this to your /etc/fstab:

david@FQDNhere:/source/path /mnt/localpath fuse.sshfs defaults,_netdev 0 0

tar

Compress

tar -cvzf the-file.tar.gz /var/www/folder-to-compress

Extract

cd /var/www/folder-to-extract-to
tar -xvzf the-file.tar.gz

wp-cli

Create Wordpress installation

wp core download --path=/var/www/blog.company.com
cd /var/www/blog.company.com
wp config create --dbname=blogdb --dbuser=blog --dbpass="royalty translation visit end"
# Create user in the database if necessary before continuing
wp db create
wp core install --url=blog.company.com --title="Company Blog" --admin_user=dbirks --admin_password="blue engineer passage nor" --admin_email=dbirks@company.com

zpool

Import by disk ID

zpool import -d /dev/disk/by-id/ tank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment