Top 20 OS X command-line secrets for power users

By Mel Beckman, InfoWorld |  Software, command line, Mac OS X

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 -9 option.

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

12. 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 -p. OK, -t isn't for "tiny" -- it's for "thumbnail." But thumbnails are tiny.

$ qlmanage -p OnlyCopyOfCriticalBusinessPlan.rtf

13. 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@remotesystem:filepath, where 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.

A neat feature of scp is that you can copy in either direction: Give the local file descriptor first to copy from local to remote; give the remote file descriptor first to copy from remote to local. The examples below show both methods, as well as how to copy entire folder hierarchies.

To copy from a local current directory to the remote system:


Originally published on InfoWorld |  Click here to read the original story.
Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question