Mac OS command line goodies

I always love doing things without my fingers leaving the keyboard. So, the more I can do from my terminal, the better. Over the years, I’ve come to like quite a few really handy commands.

Open files

Open most files as if you double clicked on it in Finder:

open usage_report.pdf

Wanna open Finder where you are in terminal?

open .

Emailing

Emailing output to yourself (you need to enable postfix first):

ps aux | mail -s "Subject line" me@example.com

You should be able to check if the email has been placed in queue:

mailq

You should see something like this if you’re quick (before it gets sent):

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
6762CA18F19*   20039 Sat Jun  9 20:12:03  root@macbookpro.local
                                         me@example.com

-- 19 Kbytes in 1 Request.

Oh this works on any Linux with mailx and local mta installed.

Clipboard manipulation

How about copying something in terminal to clipboard?

cat some_text.txt | pbcopy

You can then use Ctrl+V anywhere. And if you want to past from clipboard:

pbpaste > from_clipboard.txt

Other misc tools

Current Mac version:

sw_vers

Profiler information:

systerm_profiler

Use the Spotlight engine:

mdfind textedit

Screencapture (full tutorial here):

screencapture ~/Desktop/mycapture.jpg

That’s it! Now go have fun!