adam.nz aboutpostsprojectscontact
A man casting a shadow over a wall covered in project nerdy text.

When I was learning Unix in the early nineties I struggled to understand and remember the syntax of commandline tools. To help myself learn, each time I discovered a new command, I’d record each new success so I had a known good starting point for the next time.

Initially I kept these notes in ~/etc/ so they were easy to grep. Later they moved to a wiki page where they continued to flourish, and then finally to my WordPress site where they languished … until (hopefully) now!

Over the years I've kept the habit because it continues to be useful.

101 Recently Updated Gists

Take a screenshot of a website (details).
Resize the filesystem /data (/dev/xvda3) to a larger than 32bit filesystem. Note the first resize2fs only converts to a 64 bits, the second actually resizes the filesystem.
Disable .DS_Store and AppleDouble files on network and USB devices.
My X console
Use sftp to connect to leia.spack.org using gateway.spack.org as a jump host.
Displays a macOS notification (can change it to an alert by setting the type of alert for Script Editor in System Preferences > Notifications.
Recursively compare two folders and see differences in a format useful to humans.
List all local snapshots and then delete them.
Load a CSV into an in memory SQLite database and then do a SQL query on the data (details).
Delete cached files in ~/Library/Caches/Homebrew/
Sort of line Linux strace only in a top form and not really the same. Shows information about PID 1234
Use the time command to see how long a process takes to run. Output is formatted by the TIME variable (long format elapsed time). Details here.
Use the Bash builtin time to see how long a process takes to run. Output is formatted with the TIMEFORMAT variable (3 decimal places, long format, Elapse time). Details here.
How to clone a repo and then take it back to a specific branch.
Print the list of dates between 2010-01-01 and 2010-01-10 skipping weekends. Just part of the amazing dateutils package.
Generate SSHFP DNS entries for a host remotely.  See also sshfp2cf for automatically creating SSHFP records on Cloudflare.
My X console
Resizes a directory full of images to thumbnail size suitable for incorporating into a “life poster” (see comment by Mark Pilgrim).
Zsh trick for checking to see if a command exists without spawning a shell.
Flush DNS cache on Catalina.
Boot from USB stick via Grub (details).
Print the last, colon-delimited field of /etc/passwd. This works because NF is the number of fields (eg. 7 for /etc/passwd) and so this is the same as print $7.
View Caprover logs
Broadcast a DHCP client request with the client ID of "heyzeus" and see all responses.
Gather facts from all configured hosts (replace all with a hostname to run against a single host).
Takes standard in (from echo in this case) and replaces all instances of foo with BAZ.
Connect to smtp.spack.org:587 and initiate an SMTP STARTTLS session. More OpenSSL examples here.
Un-rot13 a message, and it works in pine if you enable the | command
Prints date thirty minutes ago
Test NFS locking semantics.
Update UFW firewall to allow all TCP traffic to ports 80, 443 and 8080-8090 inclusive and adds a comment for the rule.
Provides a top-like view of network traffic. Shows only TCP traffic on WiFi interfaces from processes named java or httpd.
Forward all traffic, including DNS, over an ssh tunnel.
Add to `.zshrc` to automatically start a tmux session on login.  If there is an existing session, it will attach, otherwise it'll spawn a new tmux session.
Zip the list of files that come from stdin.
Generate a list of all 1Password groups and the vaults which they are mapped to.
Restart Caprover
How to simulate bash commandline arguments.
Bootstrap Chezmoi in new ${HOME}.  Download binary, install dotfiles from Github user adamshand using SSH authentication, and then delete downloaded binary.
installs onto the /mnt mounted device using etc/lilo.conf as the source file.
How to break out parts of an absolute file path in Bash.
On every host defined in the Ansible inventory file, append foo.rsync.net’s SSH host key to root’s known_hosts file.
Download an archiveable copy of a website using wget.
Remove all files which aren't managed by Git.
Set awk field delimiter to use a character class (be either <space> or <period>).
Case-insensitive searching with gawk by setting builtin variable.
Add to your ~/.zshrc and then you can search these gists from the shell with: gists <keyword>
Broadcast a DHCP client request with a MAC address and see responses from all DHCP servers.
(panther) Revert focus follow mouse back to normal off setting by deleting the change.
Put a <p> at the beginning of every paragraph
Transparently SSH to a second box via a first one. Very useful for opening a shell on a host which isn’t reachable from your current network.
List all tags (versions) available for a Docker image at hub.docker.com.
Mailman page to modify individual subscriptions
Provide ssh password on commandline so you script commands like rsync.
Split blah.log into multiple gzip’d files each 1000 lines long.
Stuff
Run ansible-playbook with gateway.spack.org as an SSH jump host.
Download the file and keep the file if the transfer gets interrupted allowing it to be resumed where it left off.
Use the BitWarden commandline to retrive an item and then jq to only print the password. More information at ryan.himmelwright.net.
List Homebrew packages which were installed manually (as opposed to pulled in as a dependency of something else).
Prints hardware info
Renames all files listed to YYYY-MM-DD_HH-MM-SS (where date is when the picture was taken via EXIF data).
Change password for user adam from the commandline on a Dockerised NextCloud installation.
Clone a git repository into a non-empty directory (note that this overwrites exiting files).
Will delete all packages which have only been partially removed (eg. removed but not purged). Replace purge with search to get a list of partially removed packages.
If you can’t use ssh-copy-id to upload your ssh key to a remote host you might be able to use this.
Turn on a systemd service at book (I think, need to read systemd docs …).
Installs SSH key for passwordless SSH.
As the user www-data run the command php console.php files:scan –all on the container “nextcloud-app”.
Converts the IP 10.0.2.254 into hex.
New tool built into macOS 12 (Monterey) to test quality of internet connection (some details at danpetrov.xyz). #speedtest
Print headers and contents of whoami.spack.org to standard out, but follow and show any redirects.
Reset the MBR (master boot record). This doesn’t clear the MBR it restores it to a factory default (or something like that??).
Create an SSL certificate for mera using Cloudflare DNS challenge. Format of cloudflare.ini is described here. Requires installing certbot and python3-certbot-dns-cloudflare packages in Ubuntu.
Add to your websites /robots.txt to disable OpenAI's GPT bot from scraping your site.
Build a composite docker compose file by overlaying volumes-cached.yml over the top of docker-compose.yml.
Two different ways to use awk to print the entire line except the first field.  The first option is simpler but leaves a leading space.
Retry a command 5 times, waiting for 15 seconds before retrying.
Copy ssh key to leia via the jump host gateway.
Redirect stderr to stdout
Look up TXT records for spack.org using DNS-over-TLS from the DNS server dns.spack.org.
remove control characters from man output
Disable X11 starting on boot with GDM3 / systemd. Use get-default to read current setting. To restore X11 use graphical.target.
Start up OpenLDAP pointing explicitly to the config file and setting debugging to my preferred setting.
Fix slow performance of macOS addressbook/contacts app. Only works for contacts stored locally, for CardDAV clients just remove contacts via System Settings > Internet Accounts (source).
Shows harrdware information on the primary disk.
forges all headers
Uses mDNS to get a list of all machines on the current subnet.
Search the entire drive for files called core or dead.letter which are older then 7 days and delete them.
How to only grep stderr without redirecting all of stderr to stdout. Can use “| tee 2> >(grep …)” on a command which doesn’t support redirection.
Show all TCP traffic on port 80.
useful for debugging ntp
Python tool (domainaware/checkdmarc)for looking up DMARC and SPF record and showing any warnings.
LILO: To get to root without the root password
Submit DNS queries and get JSON answer back.
Will work with any ip not just networks
How to SSH to a Cisco switch which only supports old key exchange algorithms. The error you get without is: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
same as the host version
Tweak rclone to use as little memory as possible.
List all APFS snapshots on local disk; delete a snapshot to free up space and mount a snapshot to recover files.
views a man page without man command