linux

My Favorite One Liners

Commandline one liners that makes your workflow more productive

I use the command line every day: creating files, moving between directories, editing with vim. Along the way I’ve picked up a set of one-liners that keep coming in handy. Here are my favorites.

  1. ps aux | convert label:@- process.png

This turns your shell output into an image, which is faster than taking a screenshot when you want to share output with someone.

Note: convert is part of imagemagick. If you don’t have it, install imagemagick.

  1. curl ipinfo.io

Prints your external IP address. Worth adding as a bash alias if you check it often.

  1. git log --format='%aN' | sort -u

Lists everyone who has committed to a repo. Handy on an open source project when you want to know who has contributed.

  1. history | awk '{print $2}' | sort | uniq -c | sort -rn | head

Shows which commands you run most often. Add it to your .bashrc as an alias if you check it regularly.

  1. ls -d */

Lists directories only. Also worth setting as a bash alias for quick access.

  1. du -hs */ | sort -hr | head

Shows the 10 largest directories in your current directory.

  1. ss -p

Shows which apps are using the network.

  1. grep . *

Prints the contents of every file in the current directory, so you don’t have to cat each one individually.

  1. rm -f !(test.txt)

Removes every file in the directory except the one named in the parentheses.

  1. python3 -m http.server

Starts an HTTP server and serves your files. Handy when you want to share a file over the network.

  1. mkfifo hello; script -f hello

Shares your terminal session in real time. I recently discovered this one and it surprised me.

See it in Action

If you have a command-line tip or one-liner of your own, share it in the comments below. I would love to check it out.

To get new posts by email, subscribe to the newsletter.