Encode or Decode base64 from the Command Line

If you have ever needed to quickly decode or encode base64, Linux has a command line utility called base64 that works great. I’ll show you how it works!

To encode text to base64, use the following syntax:

$ echo -n 'codediary.net rocks' | base64

To decode, use base64 -d. To decode base64, use a syntax like the following:

$ echo -n Y29kZWRpYXJ5Lm5ldCByb2Nrcw== | base64 -d
codediary.net rocks

Note: if on OS X, use capital D:

echo -nY29kZWRpYXJ5Lm5ldCByb2Nrcw== | base64 -D

Find and kill process port on macOS

  1. Using netstat
    netstat -vanp tcp | grep 3000
  2. For macOS and newer (or if your netstat doesn’t support -p), use lsof
    lsof -i tcp:3000
kill -9 <PID>

How to automatically save screenshots to Google Drive on macOS

Saving screenshots to Drive automatically

  1. Create a new folder called “Screenshots” in your Google Drive.
  2. Open Terminal.
  3. Run the following commands:
defaults write com.apple.screencapture location ~/Google\ Drive/Screenshots/
killall SystemUIServer

Now screenshots will be saved to the Screenshots folder in your Google Drive, not the desktop.

Remove outdated installed versions of Homebrew packages

The cleanup (brew cleanup) command will remove outdated installed package versions. To affect a particular package/formula, you may supply a formula name like so: brew cleanup $FORMULA. To simulate cleanup, i.e. see what would be removed, you may use the -n option: brew cleanup -n.