Kenyon Ralph

One-liners

One-liners I have created or found useful.

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