Understanding the UNIX Commands and File Organization


The UNIX commands and the file systems get a fair coverage in this book. To make use of that coverage, you must understand the basic command structure and the general organization of files on a UNIX system.

The UNIX Command Structure

A command is the text that you type after the command prompt on the command console. Issuing a command involves typing the command on the command prompt and pressing RETURN on the computer keyboard. A command has a structure. It is, in general, composed of the following elements:

  • Name. The name of the command specifies the action to be performed. This is the name of a program that: would be executed when you issue the command. The name is always the first element of a command.

  • Option. This is a command modifier in the sense that: it specifies the way in which the action (specified by the command name) would be performed. There may be more than one option in a command. Options usually begin with a hyphen (-). In the OS literature, options are also called switches. Options generally follow the name.

  • Argument. Arguments usually specify the target of the action. For example, if the command instructs to display the content of a directory, the argument would be the name of the directory whose content is to be displayed. Arguments often follow options in the command. Arguments are also called parameters in the literature.

Following is the syntax of a UNIX command:

    $ <commandName> [<options>] [<arguments>] 

The symbol $ specifies the prompt and is already there on the console. The <options> specifies a list of options, and the <arguments> specifics a list of arguments. The square brackets around <options> and <arguments> indicate that these elements are optional. For example, the following command displays the names of the files in the directory named mydir in the long format.

    ls -l mydir 

The command name ls specifies that a list of files should be displayed, the option -l specifies that the display should be in the long format, and the argument mydir specifies the name of the directory whose files should be displayed. If the directory name is not specified, the current directory is assumed by default. You type ls -l mydir after the prompt and press RETURN. The command is issued. The important basic points about UNIX commands are summarized below:

  • In a command:

    • There must be a space between any two elements.

    • There must not be any space within the same element.

  • The name of a command is a required element. The other two elements are often optional. If not given, their default values are used.

  • UNIX commands are case sensitive.

When a command is issued, it executes a program that interacts with the kernel through a shell to do its job, as shown in Figure 1-3.

image from book
Figure 1-3: Relationship among the commands, shells, and kernel

On the Job 

Solaris provides both the options GUI and the command console for the user to interact with the OS.

You use the commands to interact with the operating system to perform various tasks. Quite a few of those tasks involve browsing through the files on your system. The files on a UNIX (and therefore Solaris) system are organized into a directory tree, so you should become quite comfortable with the concepts related to the directory tree.

Understanding the Directory Tree

One important task of an operating system is to manage files. The UNIX operating system keeps the files in a hierarchy called the directory tree. You can use a number of commands to manage files in the directory. Before you do that, you should be familiar with the following concepts related to the directory tree:

  • File. A file is the smallest container of data. In other words, the digital (computer) data is stored in files. Each file has a name. In UNIX, the file names are case sensitive. For example, myfile and myFile are the names of two different files. File in UNIX is a very general concept. The files are of the following types:

    • Regular file. Such a file contains data. The text files, binary files, and programs are examples of regular files.

    • Special file. I/O devices are also treated as files in UNIX.

    • Links. A link is a mechanism to allow several file names to refer to the same file on the disk.

    • Directory. This is a binary file containing the list of other files; it may include other directories as well. Files are organized into directories. Any file exists in some directory, which is a UNIX equivalent of folder in the Windows OS.

  • Storage device. The files are stored on a storage device such as a hard disk, a floppy disk, a CD-ROM, or a tape.

  • File system. The way an operating system organizes files on the storage device is called a file system. The operating system uses a file system to store, locate, and retrieve the data in a convenient and efficient fashion. The file system is maintained on a storage device.

  • Directory. Files are organized into directories. Any given file exists in some directory. Directory is a UNIX equivalent of folder in the Windows OS.

During OS installation, a file system is created. The layout of the file system is in the form of a hierarchical tree with the root directory (/) as the root of the tree. This hierarchy is called (inverted) directory tree with root (/) at the top. Part of the hierarchy created during installation is shown in Figure 1-4. The root directory (/) contains subdirectories including bin, etc, export, and home. These subdirectories may contain their own subdirectories, and so on. A file exists inside a directory (or a subdirectory).

image from book
Figure 1-4: A very small part of the directory hierarchy created during Solaris installation (the directory jkerry is a fictitious directory name that you can create inside the home directory; it's not part of the directories automatically created)

When you log into your system, you are put into your home directory as a starting point. From there on you can move around in the directory tree, described as follows:

  • You are here. When you are browsing the directory tree from the command console, there is a concept of being in a directory called current directory. It is important to know in which directory you currently are. This directory would work as a default directory for some commands. If your command prompt does not indicate where you are, you can find out by issuing the command:

     pwd 

  • Path. The path is the address of a file or a directory on the directory tree. No two files in a directory tree may have the same path. The path contains a series of names of directories separated by a forward slash (/) and ending in the name of the directory or the file being addressed. For example, a file passwd in the directory etc in the directory tree shown in Figure 1-4 may be addressed as: /etc/passwd. The path indicates that the file passwd exists inside the directory etc, and the directory etc exists inside the root directory /. A path may be absolute or relative.

    • Absolute path. The path that starts from the root directory is called the absolute path. Each file or directory may have only one absolute path. For example, the absolute path for the directory password is /etc/password, as shown in Figure 1-4. A directory or a file may be accessed from anywhere on the tree using its absolute path. The absolute path always starts with /.

    • Relative path. The path that starts from the current directory (where you currently are on the command prompt) is called the relative path. The relative path of a file depends on where you are trying to access it. For example, if you are in the root directory (/), the relative path to home is home, and to jkerry is home/jkerry. The double dots (..) take you one level up in the tree. For example, the relative path to the passwd file from the jkerry directory is ../../etc/passwd. The relative path never starts with /.

On the Job 

The absolute path of a file or a directory always starts with a forward slash (/), and a relative path never starts with the forward slash.

Now that you understand the basic command structure and the concepts related to the directory tree, you can roll up your sleeves to engage in some hands-on experience with your Solaris machine.




Sun Certified System Administrator for Solaris 10 Study Guide Exams 310-XXX & 310-XXX
Sun Certified System Administrator for Solaris 10 Study Guide Exams 310-XXX & 310-XXX
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net