Skip to content

Instantly share code, notes, and snippets.

@roosto
Created August 5, 2018 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roosto/8a81d90953084e410e1301c5e7e85890 to your computer and use it in GitHub Desktop.
Save roosto/8a81d90953084e410e1301c5e7e85890 to your computer and use it in GitHub Desktop.
A quick guide for useful unix commands for use in macOS

macOS & Unix: Making the World’s Best Desktop Even Better

General Tips

  1. Drag a file onto the terminal to get its path put on the command line
  2. In the Finder ⇧⌘G gives a dialogue box to open a location, that can use tab completion.
  3. Pressing / or ⇧⌘G in any file picker dialogue will give you the same file location dialogue box.
  4. Show/hides hidden files in a save dialogue box: ⇧⌘.

Homebrew

You need this. Like now.

Why are you waiting? Install Homebrew

Specific Utilities

pbpaste(1) and pbcopy(1)

pbpaste: output contents of the “pasteboard” to STDOUT pbcopy: write STDIN to the pasteboard

open(1)

Open a file or folder, as if it has been double clicked on in the Finder. Or a URL in the correct application.

Common uses:

open . # open current working directory in Finder
open -a Mail some-file.txt # open Mail.app, creating a new blank message with some-file.txt as an attachment
open http://daringfireball.net/ # open the most essential website for all Apple related news
open -a MyFavoriteEditor -W -n # -W: wait until quit, -n: open new instance. This is suitable to use for your VISUAL or EDITOR

More from Brett Terpstra on open(1)

say(1)

Text to speech from the command line.

If there is an xkcd cartoon on the topic, you know that it’s worth knowing about.

caffeinate

Keep your mac from sleeping, or wake it if it is asleep.

defaults write com.apple.screencapture location ~/Screenshots

TidBITS has more on Quick Look, including plugins for other file types.

mdfind

Search spotlight database.

mdfind -name query # search file names only
mdfind -0 # ASCII NUL after each file for piping output to other utils like `xargs -0`
mdfind -onlyin ../path/to/dir # limit search to specified directory

Quick Look

Open Quick Look from the command line. (This is one you might want to make a bash alias for).

qlmanage -p my-pretty-picture.jpg
alias qlook 'qlmanage -p' # create bash alias

Apple Support has a primer on Quick Look, in case you don’t know about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment