One-liners I have created or found useful.
- sed one-liners
- awk one-liners
- Sum a column of number output, like the output of
grep --count
: pipe it toawk '{sum+=$1}END{print sum}'
- Read numbered log files (as generated by logrotate) sequentially:
less $(echo /var/log/all.log* | tr ' ' '\n' | sort --version-sort)
- Look for a pattern in logs:
zgrep "pattern" $(echo /var/log/all.log* | tr ' ' '\n' | sort --reverse --version-sort)
- Look for a pattern in logs:
- Make a PTR record:
arpaname
- Find -doc packages that aren’t installed:
aptitude search '~RBsuggests:~i!~i~n-doc'
- Long version:
aptitude search '?and(?broken-reverse-suggests(?installed), ?not(?installed), ?name(-doc))'
- aptitude search term reference (in aptitude-doc-en)
- Long version:
- Mount a USB stick on FreeBSD:
sudo mount -t msdosfs /dev/da0s1 /mnt
- Mount a USB stick on Linux:
sudo mount -t vfat /dev/sdb1 /mnt
- Show an ssh host key fingerprint:
ssh-keygen -l -v -f /etc/ssh/ssh_host_ed25519_key.pub
- Count dependencies of a deb:
dpkg-deb --field filename.deb depends | tr --delete ',' | tr ' ' '\n' | wc -l
- Activate ssh-agent:
eval $(ssh-agent) && ssh-add ~/.ssh/id_rsa
sha512sum
on Mac OS X (or any system with OpenSSL):openssl dgst -sha512 filename
(with OpenSSL from MacPorts)- Get rid of “Warning: No xauth data; using fake authentication data for X11 forwarding.”:
xauth generate :0 .
- To stop the blinking cursor in GTK+-based Eclipse (on Linux at least), put the following line in
~/.gtkrc-2.0
:gtk-cursor-blink = 0
- Remove comment lines from configuration files:
grep --invert-match '^[[:space:]]*#' /etc/file | cat --squeeze-blank
- There is a more sophisticated version of
cat --squeeze-blank
in the GNU sed Info documentation.
- There is a more sophisticated version of
- Remove all blank lines:
sed '/^[[:space:]]*$/d'
- Remove comments and blank lines:
grep --invert-match --regexp '^[[:space:]]*#' --regexp '^[[:space:]]*$' /etc/file
- Bash glob for all directory entries, including hidden:
{.[!.]*,*}
- Show top 20 processes by memory usage:
ps -eo rss,vsz,pid,cputime,cmd --width 100 --sort rss,vsz | tail --lines 20
- Get ARIN whois info:
whois -h whois.arin.net "n + 127.0.0.1"
- ARIN whois query syntax:
whois -h whois.arin.net "?"
- ARIN whois query syntax:
- Get external IP address:
- IPv6 and IPv4:
curl icanhazip.com
- IPv6 and IPv4:
- Convert a hexadecimal IPv4 address, like you would see in NAT64 and DNS64, to dotted-decimal format:
printf "%d.%d.%d.%d\n" $(echo c0a8:ff01 | sed 's/://; s/../0x& /g; s/\.$//')
- Generate IPv6 Unique Local Address prefix
head -c5 /dev/random | hexdump -e '/1 "%02x "' | awk '{printf("fd%s:%s%s:%s%s::/48\n",$1,$2,$3,$4,$5)}'