One-liners I have created or found useful.

  1. sed one-liners
  2. awk one-liners
  3. Read numbered log files (as generated by logrotate) sequentially: less $(echo /var/log/all.log* | tr ' ' '\n' | sort --version-sort)
  4. Look for a pattern in logs: zgrep "pattern" $(echo /var/log/all.log* | tr ' ' '\n' | sort --reverse --version-sort)
  5. Make an IPv6 PTR record for a /64 zone (change the 16 to 20 in the cut command for a /48 zone): echo $(host 2001:470:1f05:4ef::999 | cut --delimiter=' ' --fields=2 | cut --delimiter=. --fields=1-16) IN PTR whatever.kenyonralph.com.
  6. Find -doc packages that aren't installed: aptitude search '~RBsuggests:~i!~i~n-doc'
  7. Long version: aptitude search '?and(?broken-reverse-suggests(?installed), ?not(?installed), ?name(-doc))'
  8. aptitude search term reference (in aptitude-doc-en)
  9. Mount a USB stick on FreeBSD: sudo mount -t msdosfs /dev/da0s1 /mnt
  10. Mount a USB stick on Linux: sudo mount -t vfat /dev/sdb1 /mnt
  11. Show an ssh host key fingerprint: ssh-keygen -l -v -f /etc/ssh/ssh_host_dsa_key (or ...rsa_key)
  12. Count dependencies of a deb: dpkg-deb --field filename.deb depends | tr --delete ',' | tr ' ' '\n' | wc -l
  13. Activate ssh-agent: eval $(ssh-agent) && ssh-add ~/.ssh/id_rsa
  14. sha512sum on Mac OS X (or any system with OpenSSL): openssl dgst -sha512 filename (with OpenSSL from MacPorts)
  15. Get rid of "Warning: No xauth data; using fake authentication data for X11 forwarding.": xauth generate :0 .
  16. 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
  17. Remove comment lines from configuration files: grep --invert-match '^[[:space:]]*#' /etc/file | cat --squeeze-blank
  18. There is a more sophisticated version of cat --squeeze-blank in the GNU sed Info documentation.
  19. Remove all blank lines: sed '/^[[:space:]]*$/d'
  20. Remove comments and blank lines: grep --invert-match --regexp '^[[:space:]]*#' --regexp '^[[:space:]]*$' /etc/file
  21. Bash glob for all directory entries, including hidden: {.[!.]*,*}
  22. http://stackoverflow.com/questions/1586477/bash-globbing-autoexpand-for-a-few-specific-cases
  23. Show top 20 processes by memory usage: ps -eo rss,vsz,pid,cputime,cmd --width 100 --sort rss,vsz | tail --lines 20
  24. Get ARIN whois info: whois -h whois.arin.net "n + 127.0.0.1"
  25. ARIN whois query syntax: whois -h whois.arin.net "?"
  26. Get external IP address:
  27. IPv6 and IPv4: wget -qO- icanhazip.com
  28. IPv4 only: curl ifconfig.me
  29. 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/\.$//')
  30. 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)}'