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
Change password for user
adam
from the commandline on a Dockerised NextCloud installation.Turn on a
systemd
service at book (I think, need to read systemd docs …).My X console
Finds
a.out
executablesuseful for debugging
ntp
Case-insensitive searching with
gawk
by setting builtin variable.Start up OpenLDAP pointing explicitly to the config file and setting debugging to my preferred setting.
Tweak rclone to use as little memory as possible.
Copy ssh key to leia via the jump host gateway.
Run
ansible-playbook
with gateway.spack.org as an SSH jump host.Provides a top-like view of network traffic. Shows only TCP traffic on WiFi interfaces from processes named
java
or httpd
.Show what package /usr/local/sbin/mtr belongs to.
If you can’t use
ssh-copy-id
to upload your ssh
key to a remote host you might be able to use this.Flushes the local DNS cache (useful if you’ve changed mail server IP addresses or something)
Clone a git repository into a non-empty directory (note that this overwrites exiting files).
Generate a list of all 1Password groups and the vaults which they are mapped to.
List all tags (versions) available for a Docker image at hub.docker.com.
Un-rot13 a message, and it works in pine if you enable the
|
commandFinds SUID/GUID files
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.
Recursively copy the contents of WorkPace.app and the resource forks into a compressed CPIO archive.
Look up TXT records for spack.org using DNS-over-TLS from the DNS server dns.spack.org.
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.
Will work with any ip not just networks
Stuff
How to test sending a webhook with cURL.
Download the file to a local name which matches the remote name, and if the download is interupted figure out automatically the offset at which to resume.
Python tool (domainaware/checkdmarc)for looking up DMARC and SPF record and showing any warnings.
Update UFW firewall to allow all TCP traffic to ports 80, 443 and 8080-8090 inclusive and adds a comment for the rule.
4 pg/pg to printer vger
Bootstrap Chezmoi in new ${HOME}. Download binary, install dotfiles from Github user adamshand using SSH authentication, and then delete downloaded binary.
Submit DNS queries and get JSON answer back.
Retry a command 5 times, waiting for 15 seconds before retrying.
Converts the IP 10.0.2.254 into hex.
Broadcast a DHCP client request with a MAC address and see responses from all DHCP servers.
Load a CSV into an in memory SQLite database and then do a SQL query on the data (details).
Displays a macOS notification (can change it to an alert by setting the type of alert for
Script Editor
in System Preferences > Notifications
.Provide
ssh
password on commandline so you script commands like rsync
.Boot from USB stick via Grub (details).
Resizes a directory full of images to thumbnail size suitable for incorporating into a “life poster” (see comment by Mark Pilgrim).
Split
blah.log
into multiple gzip’d files each 1000 lines long.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.List all local snapshots and then delete them.
Flush DNS cache on Catalina.
Connect to
smtp.spack.org:587
and initiate an SMTP STARTTLS session. More OpenSSL examples here.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.On every host defined in the Ansible inventory file, append foo.rsync.net’s SSH host key to root’s known_hosts file.
Reset the MBR (master boot record). This doesn’t clear the MBR it restores it to a factory default (or something like that??).
blah
Add to your websites
/robots.txt
to disable OpenAI's GPT bot from scraping your site.Installs SSH key for passwordless SSH.
Test NFS locking semantics.
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.
Download an archiveable copy of a website using
wget
.(panther) Revert focus follow mouse back to normal off setting by deleting the change.
Print the list of dates between
2010-01-01
and 2010-01-10
skipping weekends. Just part of the amazing dateutils package.My X console
Bring up a wireless wpa2 network from the command line.
Zsh trick for checking to see if a command exists without spawning a shell.
Mailman page to modify individual subscriptions
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.
Delete cached files in
~/Library/Caches/Homebrew/
Use
awk
to generate a list of usernames from a CSV list of full names by grepping the passwd
file.List all APFS snapshots on local disk; delete a snapshot to free up space and mount a snapshot to recover files.
Talk dirty to whois
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.views a man page without man command
Remove all files which aren't managed by Git.
Takes standard in (from
echo
in this case) and replaces all instances of foo
with BAZ
.As the user
www-data
run the command php console.php files:scan –all
on the container “nextcloud-app”.How to look up the IP address on a Linux host which doesn’t have any binaries to look it up for you (eg. a minimal docker host without
ifconfig
or ip
).Run a shell command as root on all servers in the webservers group.
Recursively compare two folders and see differences in a format useful to humans.
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.Remove all falsy values (everything except 🍌).
Redirect
stderr
to stdout
Trap for signals 1,2,15 and
rm
file if foundShow all TCP traffic on port
80
.Broadcast a DHCP client request with the client ID of "heyzeus" and see all responses.
List Homebrew packages which were installed manually (as opposed to pulled in as a dependency of something else).
Prints hardware info
Case-insensitive searching with awk by forcing $0 to lowercase.
Renames all files listed to YYYY-MM-DD_HH-MM-SS (where date is when the picture was taken via EXIF data).
New tool built into macOS 12 (Monterey) to test quality of internet connection (some details at danpetrov.xyz). #speedtest
Sort of line Linux strace only in a top form and not really the same. Shows information about PID 1234
How to clone a repo and then take it back to a specific branch.
Generate SSHFP DNS entries for a host remotely. See also sshfp2cf for automatically creating SSHFP records on Cloudflare.
Gather facts from all configured hosts (replace all with a hostname to run against a single host).
Use the BitWarden commandline to retrive an item and then
jq
to only print the password. More information at ryan.himmelwright.net.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
Disable
.DS_Store
and AppleDouble files on network and USB devices.View Caprover logs
Set awk field delimiter to use a character class (be either <space> or <period>).
Print all the IPv4 routes
Resends mail.
Search the entire drive for files called
core
or dead.letter
which are older then 7 days and delete them.Take a screenshot of a website (details).
Use
sftp
to connect to leia.spack.org using gateway.spack.org as a jump host.How to simulate
bash
commandline arguments.Put a <p> at the beginning of every paragraph