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
New tool built into macOS 12 (Monterey) to test quality of internet connection (some details at danpetrov.xyz). #speedtest
sets up stunnel to map ssl traffic coming into 995 to the local pop port unencrypted.
To get better font rendering on Linux, disable hinting and subpixel rendering, and enable stem darkening by adding this to your
/etc/environment
file.Mailman page to modify individual subscriptions
Blah
My X console
Update UFW firewall to allow all TCP traffic to ports 80, 443 and 8080-8090 inclusive and adds a comment for the rule.
create and mount a ramdisk
Provide
ssh
password on commandline so you script commands like rsync
.Check in all files in the current directory with no message (saves being prompted for a message for each file).
Verbose output including disks, serial numbers, cpu’s etc.
Only replace
foo.txt
with bar.txt
if it's newer, and backup foo.txt
to foo.txt~#~
before overwriting (where # is an ever incrementing number).(panther) Revert focus follow mouse back to normal off setting by deleting the change.
tells all about the package.
Raw dump, good for scripts
Converts the IP 10.0.2.254 into hex.
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
Generate SSHFP DNS entries for a host remotely. See also sshfp2cf for automatically creating SSHFP records on Cloudflare.
Set awk field delimiter to use a character class (be either <space> or <period>).
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.
Case-insensitive searching with awk by forcing $0 to lowercase.
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.
remove control characters from man output
Load a CSV into an in memory SQLite database and then do a SQL query on the data (details).
Test NFS locking semantics.
Download an archiveable copy of a website using
wget
.Create a RAM disk (
tmpfs
) with a maximum size of 50MB and read/write only by root (default is mode 1777
). See /usr/src
Restart Caprover
Use the BitWarden commandline to retrive an item and then
jq
to only print the password. More information at ryan.himmelwright.net.Flushes the local DNS cache (useful if you’ve changed mail server IP addresses or something)
Un-rot13 a message, and it works in pine if you enable the
|
commandHow to test sending a webhook with cURL.
Put a <p> at the beginning of every paragraph
Resizes a directory full of images to thumbnail size suitable for incorporating into a “life poster” (see comment by Mark Pilgrim).
Shows a virtual addresses actual delivery point
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.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.useful for debugging
ntp
same as the host version
installs onto the
/mnt
mounted device using etc/lilo.conf
as the source file.List all local snapshots and then delete them.
views a man page without man command
Remove all falsy values (everything except 🍌).
Use
awk
to generate a list of usernames from a CSV list of full names by grepping the passwd
file.Start up OpenLDAP pointing explicitly to the config file and setting debugging to my preferred setting.
Clone a git repository into a non-empty directory (note that this overwrites exiting files).
The
-t 10
is just in case a user is actually logged in to the test system, not that 10 seconds gives them much time to do anything but freak out. The -c
is just so they ask me what an “id10t system error” is.Uses mDNS to get a list of all machines on the current subnet.
Bash function (eg. for
Usage: apt-cache –names-only search redis | flaunt ^redis
~/.bash_profile
) to highlight any matching text. Usage: apt-cache –names-only search redis | flaunt ^redis
Take a screenshot of a website (details).
View Caprover logs
Print all the IPv4 routes
Copy ssh key to leia via the jump host gateway.
Search the entire drive for files called
core
or dead.letter
which are older then 7 days and delete them.Upgrade Debian
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).Provides a top-like view of network traffic. Shows only TCP traffic on WiFi interfaces from processes named
java
or httpd
.If you can’t use
ssh-copy-id
to upload your ssh
key to a remote host you might be able to use this.Will work with any ip not just networks
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
.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.Forward all traffic, including DNS, over an ssh tunnel.
How to break out parts of an absolute file path in Bash.
Change password for user
adam
from the commandline on a Dockerised NextCloud installation.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
).Redirect
stderr
to stdout
Broadcast a DHCP client request with a MAC address and see responses from all DHCP servers.
Tweak rclone to use as little memory as possible.
Same as above only bind as
uid=adam
and prompt for the password (-w <password>
to specify on the command line)Recursively compare two folders and see differences in a format useful to humans.
Remove all files which aren't managed by Git.
Stuff
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.
How to simulate
bash
commandline arguments.LILO: To get to root without the root password
Dumps the structure and the data of all databases to
mysql_all.sql
(including all the MySql specific create commands)Prints date thirty minutes ago
Delete cached files in
~/Library/Caches/Homebrew/
Show all files belonging to the package org.rudix.pkg.mtr.
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.
Show what package /usr/local/sbin/mtr belongs to.
blah
4 pg/pg to printer vger
Disable X11 starting on boot with GDM3 / systemd. Use
get-default
to read current setting. To restore X11 use graphical.target
.Make a /tmp/filename for “search for” and replace it with “replace with”
Retry a command 5 times, waiting for 15 seconds before retrying.
To copy a disk image onto a floppy
Grep my IkiWiki blog for any line beginning with
[[!tag
and strip off the formatting and print out one tag per line.Gather facts from all configured hosts (replace all with a hostname to run against a single host).
Gives you NSblahblah-HST (can use IP# too)
Show all grants for the user
iaddressbook
on the host localhost
.Prints hardware info
Generate a list of all 1Password groups and the vaults which they are mapped to.
Look up TXT records for spack.org using DNS-over-TLS from the DNS server dns.spack.org.
blah
similar to stunnel command, much more verbose
Zip the list of files that come from
stdin
./etc/apt/apt.conf
line for apt through a proxy.Display directory tree.