Got any tips or tricks for Terminal in Mac OS X?
One tip or trick per answer.
My favorite is
open .
Opens the folder you're currently browsing in Finder. You can also pass URLs, images, documents or else to open
.
If you specify a program name with -a you can pass the URL, image, document or folder to that program instead, e.g. open -a Preview image.png
, overriding the default program set for the filetype.
Please don't post duplicates. Search in the question like this: inquestion:this ls -l
Mac OS X specific answers only.
You can hold option and click a position in the current line to move your cursor to that position.
pbcopy
and pbpaste
:
# Copy output of command to clipboard
grep 'search term' largeFile.txt | pbcopy
# Abuse clipboard contents
pbpaste | sed 's/ /%20/g'
# get rid of the text attributes when you copy formatted text
pbpaste|pbcopy
opensnoop
is my new favorite utility. It uses DTrace to show you all of the files that are being accessed on your system, you need to execute it with superuser privileges
sudo opensnoop
You can also watch what a particular process opens by passing in the PID:
sudo opensnoop -p PID
Or watch a particular file to see who's opening it:
sudo opensnoop -f /etc/passwd