Useful UNIX Commands
Manipulating files and viewing folder content is fun, but the UNIX command line is capable of so much more! Focus your attention on some of the other useful tasks that you can perform with the command line.
Mac OS X comes stocked with a full set of useful commands. You can discover many of the commands that are installed by viewing the files in /usr/bin. Type cd /usr/bin to navigate there. Other locations to peruse include /bin and /usr/local/bin.
Calendar command in UNIX
The cal command displays a calendar in text form. Simply entering cal at the prompt displays a calendar for the current month.
Append a number to the cal command to display a 12-month calendar for that year. The number that follows the cal command is the year for which you’d like to see a calendar. For example, to view a calendar for 1970, type cal 1970.
Append a month number and a year number to display the calendar for that month. For example, to view a calendar for April 2012, type cal 04 2012.
Use the –m flag to specify the current year, as in cal –m 08 for August of this year.
Another useful command that’s related to the cal command is date. Type date at the command line to display the day, date, time, and year based on your computer’s settings.
WHITEDRAGON:~ markchambers$ date Mon Jan 15 11:32:20 CDT 2011
Processes in UNIX
Have you ever been curious as to why your hard drive seems to spin and grind on occasion while your system is seemingly inactive? Mac OS X sometimes has a lot of stuff going on behind the scenes. To discover just what your computer is busy doing at any time, use the top command to display all the actions that your computer is currently performing.
These activities are called processes; some are created when you launch applications, and others are simply tasks that Mac OS X has to take care of to keep things running smoothly.
Besides listing the names of the various processes currently in use, top tells you how much of your CPU is being devoted to each process. This lets you know what process is currently hogging all your computing power.
Sometimes a process stalls, effectively freezing that action. By using the top command to find the Process ID (PID) of the offending process, you can halt the process. Simply use the kill command followed by the PID of the process that you want to stop. (The man help page for the kill command gives more options that may help terminate stubborn processes with prejudice.)
Do not go killing processes with a cavalier attitude! Although Mac OS X is extremely stable, removing the wrong process — such as init or mach_init — is rather like removing a leg from one of those deep-sea drilling platforms: the very definition of Not Good.
You could lock up your system and lose whatever you’re doing in other applications. If you simply want to shut down a misbehaving program, go graphical again (at least for a moment) and use the Force Quit menu command from the Apple menu.
Like top, another handy command for examining process info is ps (short for process status). Most often, you’ll want to append a few flags to the ps command to get the information that you desire. For example, try the following command:
The man page for ps explains what each flag means.