Breaking the Ice with Your Solaris Machine


In this section, you will try some commands to break the ice with your Solaris machine. We are assuming that you have installed Solaris on your machine following the instructions given in Chapter 2 or that you have access to a machine that has Solaris installed on it.

In order to use the Solaris system, you need to log into it.

Logging In and Logging Out

A standard login session (or work session) is the interval starting with the time you log in to the system and ending with the time you log out. The multiuser environment of Solaris requires that you type in your login name and password as your identification each time you want to log into the system. So you, the system administrator, need to create a login name and a password in order to enable a user to use the system.

Before you log in to the system, your screen should display the following:

    <hostname> console login: 

Type in the login name at the prompt and press RETURN. For example, assume the hostname of your machine is dem, and your login name is jkerry; you would type jkerry at the prompt:

    dem console login: jkerry 

When you press RETURN, the system requests your password as follows:

    dem console login: jkerry    Password: 

Type in your password at the prompt and press RETURN. Note that, as a security feature, the system does not display your password on the screen as you type it.

On the Job 

The key referred to as RETURN in this book may be labeled ENTER on some keyboards, and vice versa.

When you initially log in to the system, you actually log into a shell that is automatically started for you. Your command prompt will indicate the shell, and this shell is called your login shell. The Bourne shell is the default shell, but it can be changed. The availability of some commands or programs may depend upon the login shell you are using.

When you have finished, you are done with your session and are ready to exit the system. You can log out by typing exit on the command prompt:

    exit 

When you press RETURN, the system once again displays the login prompt:

    <hostname> console login: 

The appearance of the login prompt indicates that you have successfully logged out and the system is ready for a user to log in.

Now that you know how to log in and log out of the system, you can try a few commands after logging in.

Getting Started with Issuing Commands

When you log into your machine, you will be put into your home directory, which is the directory created when your account was created. You can, if you are a typical user, create directories and files under your home directory. That is, your directory tree starts from your home directory. A command prompt will appear that will depend on the shell that was started when you logged in, as shown in Table 1-5. Of course, these prompts are by default and can be changed by the system administrator—that is, you.

Table 1-5: Command prompts displayed by different shells for an ordinary user and a superuser

Shell User

C

Bourne, Korn

Ordinary user

<machineName>%

$

Superuser

<machineName>#

#

In this section, we will assume that you are logged into the Bourne shell, and hence your command prompt is $. When you see this command prompt, it means the system is waiting for a command from you. Issuing a command means typing the command at the command prompt and pressing RETURN. The command is not issued until you press RETURN. This means you can retype (or correct) your command before pressing RETURN. Let's try a few commands.

Find out in which directory you are by issuing the following command:

    $ pwd 

Remember, you do not type $; that is a prompt already displayed. It will display the absolute path of the directory in which you are, such as:

    /home/jkerry 

You can issue the following command to find out the time on the system:

    $ date 

The output of this command will look like the following:

    Fri Jul 08 11:25:34 PST 2005    $ 

Try the following command now:

    $ Date 

The output will look like the following:

    Date: Command not found.    $ 

This tells you that commands (and file names) in UNIX (and hence in Solaris) are case sensitive. Most commands in Solaris are in lowercase. To see the list of content (names of files and subdirectories) in the /etc directory, issue the following command:

    $ ls /etc 

Here you used the absolute path to the directory etc. Assuming you are in your home directory, directly under the /home directory you can issue the following command by using the relative path to the /etc directory:

    $ ls ../../etc 

This will obviously generate the same output as the ls /etc command. To display the whole directory tree underneath the etc directory, issue the following command:

    $ ls -aR /etc 

This will recursively display the whole subtree of directories underneath /etc with the directory names and file names. You can use the cd command to change the directory:

    $ cd <targetDirectory> 

The argument <targetDirectory> specifies the relative or the absolute path of the directory to which you want to go. The cd command without any argument takes you to your home directory. You can see a list of commands recently issued on this terminal by issuing the following command:

    $ history 

It will display an output that looks like this:

    1 pwd    2 date    3 ls /etc    4 ls ../../etc    5 ls -aR /etc    6 history 

Here are some useful tips about the commands:

  • You can issue more than one independent command in one command line by separating them from each other with a semicolon (;), such as:

        $ date; pwd 

  • To repeat the last command, just issue the following command:

        $ !! 

  • To repeat any previous command, just issue it by its history number. For example, the following will reissue the command with history number 3:

        $ !3 

You can find the history number by issuing the history command. Let's try some advanced commands now. Create a file named test.txt by issuing the following command:

    $ touch test.txt 

It will create an empty file with name test.txt. You can verify that the file is created by issuing the ls command. Now you can write the output of an ls command into the test.txt file by issuing the following command:

    $ ls /etc > test.txt 

This is called redirecting the output, and the symbol > is called the redirection operator. You can verify that the test.txt file does have the output of the ls command by issuing the following command:

    $ more test.txt 

This will display the content of the file one page at a time, and you can push the space bar to display the next page. You can also direct the output of a command as an input to another command. This is called piping. As an example consider the following:

    $ ls -l/etc | grep test 

This will pipe the output of ls -l command into the grep command, which will display only those lines of the output that contain the string test. The vertical bar (|) is called the pipe operator or pipe symbol.

Another very useful command, the wc command, can be used to count the characters, words, or lines in a file. The command has the following syntax:

    $ wc [-c] [-C] [-lw] [-m] [<filename>] 

The argument fileName specifics the name of the file under analysis. The options are described here:

  • -c. Count the bytes.

  • -C. Count characters.

  • -l. Count lines.

  • -m. Same as -C.

  • -w. Count words delimited by white space or new line character.

If no options are specified, -lwc is assumed as default. If you want to count only the unique lines (ignore the duplicates) in a file, issue the following command:

    $ uniq -u <filename> | wc -l 

The uniq -u command generates the list of unique lines and pipes it as an input into the wc command, which counts the number of lines and displays the number.

To count the number of files in a directory, you can issue the following command:

    $ ls -l | wc -l 

The ls -l will produce one line for each file, and the wc -l command will give you the line counts; hence, you have the count for the number of files in the directory.

There will be situations when you will need help regarding commands, such as when you know the name of a command but you are not sure how to use it. In this case use the man command, which will display the so-called man (manual) pages for the command. For example, if you want to know about the ls command, issue the following man command:

    $ man ls 

However, be patient. It takes a while to get used to the man pages; they may look cumbersome and sound confusing to a beginner.

The three most important takeaways from this chapter are the following:

  • An operating system is a software system that controls and manages the computer resources and acts as an agent between the user and the computer hardware, and between the applications and the computer hardware.

  • Solaris is an operating system that is one member of a family of operating systems called UNIX.

  • You interact with any UNIX operating system, including Solaris, through a shell that interprets your commands for the kernel, which is the core of the operating system.




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