
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
Verbose output including disks, serial numbers, cpu’s etc.
Case-insensitive searching with awk by forcing $0 to lowercase.
Broadcast a DHCP client request with a MAC address and see responses from all DHCP servers.
Search the entire drive for files called
core
or dead.letter
which are older then 7 days and delete them.Resizes a directory full of images to thumbnail size suitable for incorporating into a “life poster” (see comment by Mark Pilgrim).
Renames all files listed to YYYY-MM-DD_HH-MM-SS (where date is when the picture was taken via EXIF data).
Mailman page to modify individual subscriptions
Show all TCP traffic on port
80
.Add to your
~/.zshrc
and then you can search these gists from the shell with: gists <keyword>
Puts line matching
/DAILY/
into $x
, then skips to the next line and prints $x
followed by the next line. Useful for generating reports when each log entry spans two lines. Eg. line 1 and 2 get merged into line 1, and line 3 and 4 get merged into line 2 etc. (from Shannon)Broadcast a DHCP client request with the client ID of "heyzeus" and see all responses.
Deletes file called ”-weirdfile“ in current directory.
Shows detailed snapshot of utilization between the time you ran the
statit -b
(begin) and statit -e
(end) commands (only available in priv set advanced
).Download a web page to stdout, number all the spans with a class of
time-text
and pull out the text within the span’s with a class of time-text
Using the BItWarden commandline, print a random passphrase to the screen and save it to the clipboard.
Create thumbnail page with four images per column, omitting image count in caption, using captions and creating “web sized” images for display in slide page.
finds/fixes errors in
/etc/passwd
and /etc/shadow
Make a /tmp/filename for “search for” and replace it with “replace with”
Prints hardware info
blah
List all tags (versions) available for a Docker image at hub.docker.com.
Use
awk
to generate a list of usernames from a CSV list of full names by grepping the passwd
file.views a man page without man command
(MacPorts) Upgrade subversion to the latest version (without “-u” the old version won’t be uninstalled automatically)
Gives you NSblahblah-HST (can use IP# too)
Displays a macOS notification (can change it to an alert by setting the type of alert for
Script Editor
in System Preferences > Notifications
.similar to stunnel command, much more verbose
Flush DNS cache on Catalina.
Gather facts from all configured hosts (replace all with a hostname to run against a single host).
How to simulate
bash
commandline arguments.Resends mail.
Show all files attached to PID
2345
(-R
means include ppid info).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).My X console
Python tool (domainaware/checkdmarc)for looking up DMARC and SPF record and showing any warnings.
Print all the IPv4 routes
Open an interactive MySQL shell on the container
Will work with any ip not just networks
Convert Unix time to normal time.
Uses mDNS to get a list of all machines on the current subnet.
(panther) Revert focus follow mouse back to normal off setting by deleting the change.
CPU is a LDAP aware clone of the user/add/mod/del commands,
-w
means prompt for the password on the command line and the rest of the arguments are very similar to user* tools. The majority of the config can go into /etc/cpu.conf
Stuff
Download the file and keep the file if the transfer gets interrupted allowing it to be resumed where it left off.
Shows the status of currently running disk scrubs.
LILO: To get to root without the root password
Upgrade Debian
Test NFS locking semantics.
Bring up a wireless wpa2 network from the command line.
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.Trap for signals 1,2,15 and
rm
file if foundGrep my IkiWiki blog for any line beginning with
[[!tag
and strip off the formatting and print out one tag per line./etc/apt/apt.conf
line for apt through a proxy.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.Search all the data files in Sendmail’s queue for null characters and remove them. This very useful when spurious null characters crash your Cyrus LMTP process and cause your sendmail queue to backup forever.
Disable X11 starting on boot with GDM3 / systemd. Use
get-default
to read current setting. To restore X11 use graphical.target
.Break a lock as root
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
Starts queue runner using alternative directory
Retry a command 5 times, waiting for 15 seconds before retrying.
Details of disks and volumes including failed disks, rebuiding disks and hot spares.
Prints out the relevant info for all the currently available wireless access points (essid, encryption, channel, signal, bssid etc). There are other useful options as well (
-x
gives the output in XML) but the command lives in /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources
so add it too your path or link it somewhere.On every host defined in the Ansible inventory file, append foo.rsync.net’s SSH host key to root’s known_hosts file.
Disable’s linux screen saver
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
).Finds SUID/GUID files
My X console
How to break out parts of an absolute file path in Bash.
Forward all traffic, including DNS, over an ssh tunnel.
Shows package info
Copy ssh key to leia via the jump host gateway.
Remove all files which aren't managed by Git.
Update UFW firewall to allow all TCP traffic to ports 80, 443 and 8080-8090 inclusive and adds a comment for the rule.
Recursively copy the contents of WorkPace.app and the resource forks into a compressed CPIO archive.
Flushes the local DNS cache (useful if you’ve changed mail server IP addresses or something) (pre-Leopard only)
Display directory tree.
Use
sftp
to connect to leia.spack.org using gateway.spack.org as a jump host.Disable
.DS_Store
and AppleDouble files on network and USB devices.Install the Python package Jupyter using PIP. This works even though jupyter has dependencies which require upgrading the builtin macOS setuptools (which aren’t upgradable because of SIP).
Print all information (including IPTC data) to standard out.
Provide
ssh
password on commandline so you script commands like rsync
.Runs “notepad my_file.txt” as the user adam on the domain spack.org.
Changes users shell to
/bin/bash
(remember root)Turn on a
systemd
service at book (I think, need to read systemd docs …).List Homebrew packages which were installed manually (as opposed to pulled in as a dependency of something else).
Delete cached files in
~/Library/Caches/Homebrew/
If you really can’t delete a file any other way.
ls -id
means don’t go into directories and print out the inode of each file. Then we take the inode of the weird file and tell find to delete that inode.Show all grants for the user
iaddressbook
on the host localhost
.forges all headers
The same as
newaliases
Tries to run things without the binary modules which will allow to to repair really broken stuff.
Put a <p> at the beginning of every paragraph
Renames
*.jpg
listed to YYYY/MM/YYYY-MM-DD_HH-MM-SS.Redirect
stderr
to stdout
Get UUID for disk partition to add to
/etc/fstab
.blah
Zsh trick for checking to see if a command exists without spawning a shell.
View Caprover logs
Connect to
smtp.spack.org:587
and initiate an SMTP STARTTLS session. More OpenSSL examples here.Set awk field delimiter to use a character class (be either <space> or <period>).
Tweak rclone to use as little memory as possible.