Kenyon Ralph

One-liners

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)
    • Look for a pattern in logs: zgrep "pattern" $(echo /var/log/all.log* | tr ' ' '\n' | sort --reverse --version-sort)
  4. Make a PTR record: arpaname
  5. 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)
  6. Mount a USB stick on FreeBSD: sudo mount -t msdosfs /dev/da0s1 /mnt
  7. Mount a USB stick on Linux: sudo mount -t vfat /dev/sdb1 /mnt
  8. Show an ssh host key fingerprint: ssh-keygen -l -v -f /etc/ssh/ssh_host_ed25519_key.pub
  9. Count dependencies of a deb: dpkg-deb --field filename.deb depends | tr --delete ',' | tr ' ' '\n' | wc -l
  10. Activate ssh-agent: eval $(ssh-agent) && ssh-add ~/.ssh/id_rsa
  11. sha512sum on Mac OS X (or any system with OpenSSL): openssl dgst -sha512 filename (with OpenSSL from MacPorts)
  12. Get rid of “Warning: No xauth data; using fake authentication data for X11 forwarding.”: xauth generate :0 .
  13. 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
  14. Remove comment lines from configuration files: grep --invert-match '^\[[:space:]]*#' /etc/file | cat --squeeze-blank
  15. Remove all blank lines: sed '/^\[[:space:]]*$/d'
  16. Remove comments and blank lines: grep --invert-match --regexp '^\[[:space:]]*#' --regexp '^\[[:space:]]*$' /etc/file
  17. Bash glob for all directory entries, including hidden: {.[!.]*,*}
  18. Show top 20 processes by memory usage: ps -eo rss,vsz,pid,cputime,cmd --width 100 --sort rss,vsz | tail --lines 20
  19. Get ARIN whois info: whois -h whois.arin.net "n + 127.0.0.1"
    • ARIN whois query syntax: whois -h whois.arin.net "?"
  20. Get external IP address:
    • IPv6 and IPv4: curl icanhazip.com
  21. 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/\.$//')
  22. 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)}'
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. Revision History.