To open a document in its default application for file type:
$ open Documents/myword.doc
To open a document in an application other than the one for file type:
$ open -a bbedit junko.txt
To open a file in TextEditor:
$ open -e mytext.rtf
To open a URL in the default browser:
$ open http://google.com
opendiff: Compare and merge files and directores
opendiff takes two file or directory names as arguments and passes them to the little-known (because it's hidden) FileMerge utility in OS X's Utilities folder. FileMerge can find the differences between two text files, as well as compare two directories with the ability to merge them into a single directory that eliminates duplicate files. The syntax is simple and produces the display shown below:
$ opendiff Contract1.rtf Contract2.rtf
pkill: Find or signal a program or processby name
The old way of finding a running program or process (a program can spawn multiple processes having the same name) was to run the
ps command and pipe its output to grep. The
pgrep command-line utility does all that in one step: Just specify the name of the process you seek as an argument.
You can also send a signal to a program the same way using
pkill. Old Unix hands know that
kill doesn't really mean to kill the processs; normally it's just a way to send a friendly nudge to a process to, for example, ask it to restart. But if necessary,
pkill can actually kill a program if you use its
To see if Safari is running:
$ pgrep Safari
It might display:
mel 75341 0.0 0.7 ... /Applications/Safari.app/Contents/MacOS/Safari
To kill Safari (now!):
$ pkill -9 Safari
qlmanage: Quick-look a file from the command line
Say you're about to delete a file from the command line. Is it anything you might regret deleting? Check first, using
qlmanage with the
-p option to see a preview of the file's contents, using OS X's Quick Look facility that's so handy when in the GUI. Or don't. It's your career, not mine.
If you just want a tiny look, use
-t instead of
-t isn't for "tiny" -- it's for "thumbnail." But thumbnails are tiny.
$ qlmanage -p OnlyCopyOfCriticalBusinessPlan.rtf
scp: Securely copy a file between two computers
Another popular command with Linux and Unix afficianados,
scp (Secure Copy) is often overlooked by OS X administrators. Traditionally, you'd copy a file or a directory between systems using the Finder, which entails first configuring file sharing, then mounting the remote system's share point, then navigating two Finder windows to the desired source and destination folder, and finally dragging the desired files or folders from one window to the other.
You can accomplish all that in a single command with
scp, which takes two arguments: a source file descriptor and a destination file descriptor.
For local files, the file descriptor is an ordinary path to the file, which if in the current directory and consists of just the file name. The remote file descriptor has three parts, in the form of
userID is the name of the user on the remote system,
remotesystem is the name or IP address of the remote system, and
filepath is a path to the file.