OSX GUI/Unix integration

I found these great OSX tips over at this site.

The open command allows you to open files and directories directly from the shell. If you open an HTML file it will open in the default browser, if you open a directory it will open in the Finder.

Use drag-and-drop from the Finder to a Terminal window to have the Terminal paste the full path to the file into the command line at the point where your cursor is.

The pbcopy / pbpaste commands allow you to copy to or from the system clipboard to or from pipes on the command line. This means that you can exchange data between GUI applications and command line tools in both directions.

For example, if you copy some amount of text in a word processor to the clipboard and you would like to know quickly how many words, lines and characters are in the text you copied, you can use the UNIX wc command to do the statistics:

pbpaste | wc

Another example: Check if a snippet of XML code, which you edit in a GUI program like BBEdit and copy to the clibpord, is well-formed by piping it to the xmllint program:

pbpaste | xmllint –noout –

This kind of communication also works the other way around; If you want copy a list all files in your Pictures folder:

ls ~/Pictures | pbcopy

Also note the tip regarding the bbedit command line tool above.

As always, the man command is your friend. Just type man followed by the command you’re interested in to get more information.

This is cool! I never knew you could pipe between the command line and the clipboard!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s