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.
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.
curl ipinfo.io
Prints your external IP address. Worth adding as a bash alias if you check it often.
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.
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.
ls -d */
Lists directories only. Also worth setting as a bash alias for quick access.
du -hs */ | sort -hr | head
Shows the 10 largest directories in your current directory.
ss -p
Shows which apps are using the network.
grep . *
Prints the contents of every file in the current directory, so you don’t have to cat each one individually.
rm -f !(test.txt)
Removes every file in the directory except the one named in the parentheses.
python3 -m http.server
Starts an HTTP server and serves your files. Handy when you want to share a file over the network.
mkfifo hello; script -f hello
Shares your terminal session in real time. I recently discovered this one and it surprised me.
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.