Useful Commands (MacBook)

Manipulating files and viewing folder content is fun, but the command line is capable of so much more! Now I 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 what commands are installed by viewing the files in /usr/bin. Type cd /usr/bin to navigate there.
Calendar
One of my favorite command-line functions is the cal command, which displays a calendar in text form. Simply entering cal at the prompt displays a calendar for the current month, as shown in Figure 1-4.
Type cal to view a calendar for the current month.
Figure 1-4: Type cal to view 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. The result appears in Figure 1-5.
Append a month number and a year number to display the calendar for that month. For example, to view a calendar for April 2010, type cal 04 2010.
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:- date Mon Jan 15 11:32:20 CDT 2009
Type cal followed by a year to view the 12 months of that year.
Figure 1-5: Type cal followed by a year to view the 12 months of that year.


Processes

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, as shown in Figure 1-6. 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.)
The top command displays all running processes.
Figure 1-6:
The top command displays all running processes.
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 Finder menu.
Like top, another handy command for examining process info is ps (short for process). 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:
ps -aux
The man page for ps explains what each flag means. (Read more about using the man command in the earlier section “Help is on the way!”)

Next post:

Previous post: