Special Edition Using Mac OS X v10.2
| Many, many Unix commands are available, and there is no way you can do more than scratch the surface in this small chapter. However, you can learn how Unix commands work in general by trying some specific examples of useful Unix commands. Each of the following sections provides information about specific commands. For each command, you will see four areas of information about that command. First, you will read a general description of what the command does. Second, you will see the command's syntax and some of the useful options for that command. Third, you will see a more specific description of the command's effect. Fourth, you will see the steps you can take to use the command. NOTE For the commands in this section, you won't see all or even many of the options that are possible for each command. You will need to access a more detailed reference for that kind of information, such as the command's manual pages.
Learning About the Environment
When you are troubleshooting, it can be helpful to understand the environment in which you are running Unix. You can use the uname command to get information about the computer on which you execute the command. Or, you might need to check this information to make sure some software or hardware is compatible with your system. Command: uname Options: -a provides all the information about your machine; -s shows the operating system name; -n lists the machine name What it does: Provides information about various aspects of the machine on which you are running Unix
Command: env What it does: Provides extensive information about your Unix session (your Unix environment) Type env and press Return. You will see information including your Home directory, the shell you are running, the username you are using, the language being used, the application you are using to enter Unix commands, and so on. This information can get pretty extensive; scroll up the window to just below where you entered the command to see the more meaningful parts.) Viewing the Contents of Directories
You will frequently need to move up and down the directory structure to work with specific files or other directories. Unix has many commands that enable you to do so. Command: pwd What it does: Shows you the full path to your current location Use the pwd command when you aren't sure about the directory in which you are currently located. When you use the command, you will see the full path in which you are working. This can be helpful as you move around the directories if you become confused about where you are. Command: cd pathname What it does: Changes your directory location to the one in the path pathname NOTE When a specific command is listed in a step, you should ignore the period at the end of the command. For example, in the following steps, don't type the period after the command cd music in Step 1.
NOTE In a pathname, the tilde character (~) indicates that you are in your Home directory. In the previous step, you could have just entered cd ~ to move back into your Home directory.
Command: ls Options: -F differentiates between files and directories; -l shows full information for all the files in the directory What it does: Lists the contents of a directory in various formats and with various information NOTE Note that while most commands and options are in lowercase, they aren't always. For example, the -F option is different from the -f option (both are valid for the ls command).
TIP If you type the command ls la, you will also see the invisible files in a directory.
The permissions string you see at the start of each item in the full listing indicates how the item can be accessed. The first character indicates whether the item is a file (-) or a directory (d). The next three characters indicate what the owner of the file can do; r is for read, w is for write, and x is for execute. If any of these characters is the hyphen (-), that action can't be taken. The next three characters indicate the permission that the group has to the file. For example, if these characters are r-x, that would mean that other members of the group can read, not write, and execute the file. The last three characters indicate what everyone else can do. The execute permission applies to a directory. In order to access a directory, you must have both read and execute permission. If you also have w permission, you can change the contents of the directory as well. Command: file filename What it does: Indicates what kind of file filename is Type file, followed by the filename you would like information about, and press Return. Information about the file will be displayed. Changing the Contents of Directories
You can use Unix commands to change the contents of directories as well. For example, you can delete files using the rm command. This can sometimes be faster than using the Trash. Once in a while, you might not be able to use the Trash to get rid of a file; you can often use the Unix commands to accomplish the task when other means fail. Command: rm Options: -i prompts you before deleting each file; -r removes the entire directory What it does: Deletes everything that you indicate should be deleted
TIP You can't remove the current directory unless you enter the full path to it.
TIP The asterisk is a wildcard character. For example, to delete all the files in a directory that have the file extension .tiff, you can type rm *.tiff.
Command: cp What it does: Copies a file
Command: mv What it does: Moves a file or directory Type mv filename path and press Return. The file or directory filename will be moved to the location path. Command: mkdir What it does: Creates a directory
Using the Manual
All Unix commands have a manual associated with them. This manual lists the syntax for the command and defines its options; manuals can be a good reference when you are using a specific command, but can't remember an option or the command's exact syntax. Many manual pages also provide some explanation about how the command works. Command: man What it does: Brings up the manual pages for the command that you enter
It is a good idea to take a look at the manual pages for any Unix commands you use. Pay special attention to the list of options that are available for the command. NOTE Some Unix applications provide manual pages using the help argument. For example, perl--help brings up information about the perl application.
TIP Pressing the spacebar moves you down the manual page one screen's worth at a time; you can move down a manual page one line at a time by using the Return key instead.
Using Superuser Commands
As you learned earlier in the book, the root account is the fundamental user account that can do anything under Mac OS X. The root account has more access to the system than even an Administrator account does. Using this account can be hazardous to your system because when you are under root, the OS assumes that you know what you are doing and doesn't provide any checks on your activities. It is relatively easy to delete things you don't mean to or to mess up the system itself. CAUTION By entering the root account, you can do damage to your system. You should use this only when you really have to, and even then, you need to be very careful about the commands you enter while you are working on the root prompt.
However, when you need to use a specific command at a specific time that you can't do under another user account, it can be helpful to enter commands as root. Command: sudo Option: -s, which runs the command in the default shell What it does: Gets you into the root account so that you can enter a command that you can't enter under another account
TIP To return to the previous account, type exit and press Return.
Killing a Process
When a process goes wrong, it can cause problems, such as hanging, or it might start consuming tremendous amounts of processing power, thus bringing your system's performance to a crawl. Under Mac OS X, there are several ways to stop an out-of-control process. For applications, you can use the Force Quit command. At the process level, you can use the Process Viewer to force a process to quit. You can also use the powerful Unix command kill to stop a running process. Command: kill ProcessID Options: -9 kills the process no matter what; -3 quits the process What it does: Stops the process with the ID number ProcessID
NOTE If the process you are trying to kill is an Administrator process, you will have to use the sudo -s command to get into the root account before you use the kill command.
|