Вы находитесь на странице: 1из 37

SUBSECRETARÍA DE EDUCACIÓN SUPERIOR

Certificado en el Proceso Educativo ISO 9001:2000

SUBDIRECCIÓN ACADÉMICA
DEPARTAMENTO DE SISTEMAS Y COMPUTACIÓN
ACADEMIA DE CIENCIAS COMPUTACIONALES

UNIX Essentials Featuring


the Solaris 10 Operating System
(SA-100-S10)
Exercises

Roberto Hernández Pérez

01/08/2007
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Viewing and Using Components of the Desktop System

Module 1 - Using the Desktop in the Solaris 10 Operating System

Task summary and solutions

1. In order to describe the hardware components of a computer comment what are processors,
memories and devices.
2. In order to describe some Solaris operating system components comment what is a File System,
CDE interface and command line interface.
3. In order to describe the SunOS operating system comment what is a Kernel.
4. Log in to the system using CDE, later exit.
5. Log in to the system using the Telnet application from windows, later exit.
6. In order to use the desktop environment log in to the system using CDE and practice chapter 1 to 4
from “Solaris Common Desktop Environment: Guía del usuario”.

Module 2 - Using Command-Line Features and Online Help Resources

Task summary and solutions

1. To construct commands, just write the letters to form the command, for example date, in the
command line interface (CLI). If you committee a mistake, correct with backspace key. As you are
working with bash Shell, you can also construct the commands with up and down keys if these have
been previously entered. You get a command line interface by
2. To execute commands, just press enter key after you write it.
3. Practice with the following commands.
a. In order to get a command line interface (CLI), open a terminal window from your desktop
environment. It is done by pressing double click on bottom one of the mouse in a free
space of your desktop, from the menu display, choose Host item and then Terminal.
b. Command to see the date of the system.

$date
Thu Aug 2 09:50:20 CDT 2007

c. Command to see who users are connected.

$finger
(List of users)

d. Command to see who users are connected in other format.

$who
(List of users)

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 2/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

e. Command to see the calendar, only the month.

$cal
August 2007
S M Tu W Th F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

f. Command to see the calendar for 2007, just the year.

$cal 2007
2007

Jan Feb Mar


S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
1 2 3 4 5 6 1 2 3 1 2 3
7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10
14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17
21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24
28 29 30 31 25 26 27 28 25 26 27 28 29 30 31
(Output omitted for brevity)

g. Command to see June, 1962 calendar.

$cal 6 1962
June 1962
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Note: For command cal, the number 6 or 2007 are arguments. Many commands use arguments to work
properly.

h. Command to send a message to the screen.

$echo “Hola a todos”


Hola a todos

i. Command to clear the screen.

$clear

4. In order to see and use online documentation execute the man command, as an argument write
the command you want to see. Practice for the following commands
a. To see the documentation for the date command.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 3/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

$man date
Reformatting page. Please Wait... done

User Commands date(1)

NAME
date - write the date and time

SYNOPSIS
/usr/bin/date [-u] [ +format]

/usr/bin/date [ -a [-]sss.fff]

/usr/bin/date [-u] [ [mmdd] HHMM | mmddHHMM [cc] yy] [.SS]

/usr/xpg4/bin/date [-u] [ +format]

/usr/xpg4/bin/date [ -a [-]sss.fff]

/usr/xpg4/bin/date [-u] [ [mmdd] HHMM | mmddHHMM [cc] yy]


[.SS]

DESCRIPTION
The date utility writes the date and time to standard output
or attempts to set the system date and time. By default, the
current date and time is written.

(Output omitted for brevity)

b. To see the documentation for the finger command.

$man finger
(Output omited for brevety)

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 4/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Manipulating and Managing Files and Directories

Module 3 - Viewing Directories and Files

Task summary and solutions

1. In order to work with directories, you need to move through them. You use the cd command to
change directories. Directories are arranged in tree order, so each directory can have none or
many children directories but only a father directory. The upper directory is called root and is
represented by “/”. The directory where you are, is called working directory. Use the pwd command
to know what is it. You also have your own directory where you can create, rename or rename files
or directories, this directory is called home directory. You move through directories by their names.
The father directory is call “..”. If you move to any directory beginning where you are, it is said that
the movement was by relative manner and if it was since the root directory, it is said that the
movement was in absolute manner.
2. Practice movements through different directories using the following commands:

a. To see what is your working directory.

$pwd

b. To change to the root directory.

$cd /

c. Use ls command to see what files and directories exist in a directory

$ls

d. To see with more information about files and directories (long format), use ls command
with option -l

$ls –l

Note: When you see information in long format, you can determine if a file is a directory,a normal file or a
link by seeing the first column. A d represents a directory, a hyphen represents a normal file and an l
represent a link.

e. Now, to see hidden files and directories use the option –a. The hidden files or directories
begin their names with dot.

$ls –a

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 5/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Note:-a and –l are options for ls command. Many commands have options and these are preceded by the
hyphen sign. To see other options for ls command, execute the man command with argument ls.

f. Now, change to the /var directory and see all information of the files and directories.
Include the hidden files.

$cd var
$pwd
$ls -la

Note: Many options can be joined so –a and –l are the same than –al or –la.

g. Return to the father directory

$cd ..

h. Change again to the /var directory, but now in absolute manner, and see the files.

$cd /var
$pwd
$ls -la

i. Try to find bin since the root directory, and determine if it is a file, a directory or link.

It is in /bin and it is a link.

j. Try to find ftphosts since the root directory and determine if it is a file, a directory or a link

It is in /etc/dftp directory and it is a file.

3. One way to work with files is to see its contents. You see the contents of a file using different
commands like cat, more, head and tail.
4. Practice with the following commands.

a. Change to the /etc directory


b. Use cat command to see /passwd file.

$cat passwd

c. Use more command to see by pages the passwd file.

$more passwd

d. Now to see the 5 first lines of the passwd file. 5 is an option of the head command.

head -5 passwd

e. Now to see the 20 last lines of the passwd file. 20 is an option of the tail command

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 6/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

$tail -20 passwd

5. For the moment to print files is omitted cause there isn’t a printer connected. But it is done by
using lp command and the name of the file to print.

Module 4 - Changing the Solaris OS Directory Contents

Task summary and solutions

1. In order to change the directory contents, you need to create, copy, rename, move and remove
files and directories.
2. Let’s begin with the following tasks to create directories:

a. Change to your home directory.

$cd

b. Use the mkdir command to create a directory. Only the father can create children
directories. Create dir1 and dir2 directories.

$mkdir dir1
$mkdir dir2

c. Verify that the directories have been created.

$ls –l

d. Change to the dir1 directory.

$cd dir1

e. Now, create dira, dirb, .dirx and .diry directories. Note that .dirx and .diry will be hidden.

$mkdir dira
$mkdir dirb
$mkdir .dirx
$mkdir .diry

f. Verify that the directories have been created.

$ls –l
$ls -la

g. Change to the .dirx directory, check the working directory path and verify its contents.

$cd .dirx
$pwd
$ls –l

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 7/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

h. Change to the dir2 directory and check the working directory path.

$cd ../../dir2
$pwd

i. Now, create trash1 and trash2 directories and verify that if was done.

$mkdir trash1
$mkdir trash2
$ls –l

3. Now, make the following tasks to create files:

a. Change to the dir2/trash1 directory, check the working directory path and create file1 and
file2 files with touch command.

$cd
$cd dir2/trash1
$pwd
$ls -l
$touch file1
$touch file2
ls -l

Note: One way to create files is using touch command. This command creates a file with a name, an i-node
number and none contents (zero bytes size). Another way is using the output of a command, i.e. redirecting
the output to a file. The symbol used to redirect the output is “>”. The last one is using the vi editor and will
be seeing next module.

b. Change to the dir2/trash2 directory, check the working directory path and create file1 and
file2 files redirecting the output of finger and who commands.

$cd ../trash2
$pwd
$ls -l
$finger > file1
$who > file2
$ls –l

4. It is turn to copy directories, make the following tasks:

a. Change to your home directory.

$cd

b. Copy dir2 directory to tmp directory with the cp command. Verify that it was done.

$cp –r dir2 tmp


$ls –ld tmp

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 8/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Note: The cp command with option –r is used to copy files recursively, so it is used to copy directories and
of course if a directory has subdirectories, these ones are also copied.

5. It is turn to copy files, make the following tasks:

a. Change to tmp/trash2 directory of your home directory.

$cd
$cd tmp/trash2

b. Copy file1 file to filefinger file with the cp command. Verify that it was done.

$cp file1 filefinger


$ls -l

6. It is turn to move (same place) or rename directories, make the following tasks:

a. Change to your home directory.

$cd

b. Move or rename dir1 directory to newdir1 directory with the mv command. Verify that it
was done.

$mv dir1 newdir1


$ls –ld newdir1

7. It is turn to move directories to another place, make the following tasks:

a. Change to your home directory.

$cd

b. Move newdir1 directory inside of tmp directory with the mv command. Verify that it was
done.

$mv newdir1 tmp


$ls –l tmp

8. It is turn to move (same place) or rename files, make the following tasks:

a. Change to your tmp/trash2 directory of your home directory.

$cd
$cd tmp/trash2

b. Move or rename file2 file to filewho file with the mv command. Verify that it was done.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 9/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

$mv file2 filewho


$ls –l

9. It is turn to move files to another place, make the following tasks:

a. Change to your tmp/trash2 directory of your home directory.

$cd
$cd tmp/trash2

b. Move file1, filewho and filefinger files to tmp/trash1 directory with the mv command.
Verify that it was done.

$mv file* ../trash1


$ls –l
$ls –l ../trash1

Note: Observe that file1 in trash1 directory was substituted by the new one.

10. It is turn to remove or delete directories, make the following tasks:

a. Change to your tmp directory of your home directory.

$cd
$cd tmp

b. Remove trash2 and newdir1 directories with the rmdir command. Verify that it was done.
What happened?

$rmdir trash2
$rmdir newdir1
$ls –l

The directory trash2 was deleted but newdir1 was not. Because newdir1 directory has files
or subdirectories.

Note: Only the father directory can delete the children directories, but these ones must be empty.

c. To remove directories that are not empty, it is use the rm command with option –r.
Remove newdir1 directory with the rm command. Verify that it was done.

$rm –r newdir1
$ls –l

Note: You should be very carefully when using rm –r command because the files and directories once
deleted, they can not be recovered.

11. It is turn to remove files, make the following tasks:

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 10/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

a. Change to tmp/trash1 directory of your home directory.

$cd
$cd tmp/trash1

b. Delete file1 file, later the rest of files with the rm command. Verify that it was done.

$rm file1
$ls –l
$rm file*
$ls -l

c. Delete trash1 directory. Verify that it was done.

$cd ..
$rmdir trash1
$ls -l

12. In order to work with links, you should know that exist two types: hard links and soft links. Also, you
should know that a file is composed by tree elements: a name, an i-node and its contents. A soft
link, also called symbolic link, is a file that just has name and i-node. Its content is the same of the
file which it points to. To work with soft links, make the following tasks:

a. Change to your home directory and create dirx and diry directories.

$cd
$mkdir dirx
$mkdir diry

b. Change to dirx directory and create filewho file redirecting the output of who command.
Verify its i-node number.

$cd dirx
$who > filewho
$ls –li

Note: The –i option of the ls command is used to show the i-number of a file.

c. Create a soft link with the ln command. Create the filewho.softlink soft link (file) that point
to filewho file. Verify its i-node numbers, size, type and contents. What do you observe?

$ln –s filewho filewho.softlink


$ls –li
$cat filewho
$cat filewho.softlink

The i-node number are different but the contents are the same. The filewho.softlink has an
“l” instead of a “-“ in the type file field, indicating that it is a soft link. Also the size of the

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 11/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

filewho and filewho.softlink are different. The soft link file name has an arrow indicating
where the file is.

Note: The –s option of the ln command is used to create soft links of a file. The first argument is the file and
the second is the link. In a soft link, the size of the file is the sum of character composed of the path file
name.

d. Now, create the filewho.new.softlink soft link (file) in the diry directory that point to
dirx/filewho file. Verify its i-node numbers, size, type and contents. What do you observe?

$cd ../diry
$ln –s ../dirx/filewho filewho.new.softlink
$ls –li ../dirx
$ls –li
$cat ../dirx/filewho
$cat filewho.new.softlink

The same as the above incise. But now, the file where the link point to is on another
directory.

e. Everything made to any of the soft links or file itself is reflected to everyone. Change the
contents of the filewho.new.softlink file in the diry directory by the date output. Verify the
contents of dirx/filewho and dirx/filewho.softlink files. What do you observe?

$date > filewho.new.softlink


$cat ../dirx/filewho
$cat ../dirx/filewho.softlink

Both files have the same date contents.

f. But if you delete the file then the links point to a file that does not exist. So you need to
delete the links, too. If you delete a link, nothing happens. Delete filewho.new.softlink file
in the diry directory and verify the contents of dirx/filewho and dirx/filewho.softlink files.
Delete dirx/filewho file and verify the contents of dirx/filewho.softlink file. Delete
dirx/filewho.softlink file. What do you observe?

$rm filewho.new.softlink
$cd ../dirx
$cat filewho
$cat filewho.softlink
$rm filewho
$cat filewho.softlink
$rm filewho.softlink

When filewho.new.softlink is deleted, nothing happens it can be seen the contents of both
files. When filewho file is deleted, it is shown an error even thought the file exists. The error
is because the file pointed to is removed.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 12/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

13. Now turn to hard links. A hard link is a file that just has name because it is used the same i-node
and contents of the file which is pointed to. It is incremented the link count in the i-node. To work
with hard links, make the following tasks:

a. Change to your home directory. It will be used the dirx and diry directories.

$cd

b. Change to dirx directory and create filefinger file redirecting the output of finger
command. Verify its i-node and link count numbers.

$cd dirx
$finger > filefinger
$ls –li

c. Create a hard link with the ln command. Create the filefinger.hardlink hard link (file) that
point to filefinger file. Verify its i-node numbers, link count, size, type and contents. What
do you observe?

$ln filefinger filefinger.hardlink


$ls –li
$cat filefinger
$cat filefinger.hardlink

The i-node number, the type, the size and the contents are the same. Both files increment
the link count to two.

d. Now, create the filefinger.new.hardlink hard link (file) in the diry directory that point to
dirx/filefinger file. Verify its i-node numbers, link count, size, type and contents. What do
you observe?

$cd ../diry
$ln ../dirx/filefinger filefinger.new.hardlink
$ls –li ../dirx
$ls –li
$cat ../dirx/filefinger
$cat filefinger.new.hardlink

Note: When a file is created, it has a hard link by default.

The same as the above incise. But now, the link count is three.

e. Everything made to any of the hard links or file itself is reflected to everyone. Change the
contents of the filefinger.new.softlink file in the diry directory by the date output. Verify
the contents of dirx/filefinger and dirx/filefinger.hardlink files. What do you observe?

$date > filefinger.new.hardlink

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 13/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

$cat ../dirx/filefinger
$cat ../dirx/filefinger.hardlink

Both files have the same date contents.

f. When you delete a hard link or the file itself, it only decrements the link count, unless you
delete the last one. Delete filefinger.new.hardlink file in the diry directory and verify the
link count and contents of dirx/filefinger and dirx/filefinger.hardlink files. Delete
dirx/filefinger file and verify the link count and contents of dirx/filefinger.hardlink file.
Delete dirx/filefinger.hardlink file. What do you observe?

$rm filefinger.new.hardlink
$cd ../dirx
$ls –li
$cat filefinger
$cat filefinger.hardtlink
$rm filefinger
$ls –li
$cat filefinger.hardlink
$rm filefinger.hardlink

Only decreased by one the link count, the contents was the same.

14. Delete dirx and diry directories.

$cd ..
$rmdir dirx
$rmdir diry

Module 5 - Using the vi Editor

Task summary and solutions

1. In order to describe the fundamentals of the vi editor, comment its characteristics and some of its
main commands.
2. In order to modify files by using the vi editor, do the following commands:

a. Change to your home directory. In that directory you have permission to write files.

$cd

b. Create the file testingvi

$vi testingvi

c. Always press the ESC key to change to command mode of vi, so press ESC and then the key
“i” to insert a text. Write the following lines. It doesn´t matter if you committee a mistake.

This text is typed to test

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 14/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

the i command to insert text.

d. Press ESC key and then the key “o” to open a line below and put in insert mode. Write the
following lines (The first line you write is empty, i.e. press Enter key).

Now, it is testing the o command to open a line below


You use the O command to open a line above.

e. Now, you can move through the text by pressing the arrow keys, do some movements.
f. Put at the end of the first line, and press ESC key then the key “a” to add text. Write the
following text.

and use

g. Now, put and the end of text “below” and add a “.”.
h. In order to number the lines, press ESC then “:” and write set number
i. In order to delete the number of the lines, press ESC then “:” and write set nonumber
j. To replace a character, use the “r” command.
k. Put in the letter “c” of the phrase “the O command”. Then press the key “r”, later, type the
capital “C”.
l. To replace many characters, use the “R” command.
m. Put at the beginning of the word “use” in the first line. Then press the key “R”, later, type
“show”
n. To delete character, use the command “X” to delete at the left and the command “x” to
delete to the right.
o. Put in whatever place of the phrase “the o command”. Then press the key “x”, one, two or
three times. Now with the key “X”, one, two or three times. So you delete “the o
command”.
p. To save file and exit, press ESC then write “:wq”. The “w” is for write and “q” for quit.

3. You file should looks like this:

$cat testingvi
This text is typed to test and show
the i command to insert text.

Now, it is testing to open a line below.


You use the O Command to open a line above.

4. Modify the same file, but now with other commands.

Table 5.1 Other commands of vi.

Command Action
Dd Delete a line a save it to the buffer
Yy Save the line to the buffer
P Insert a line contained in the buffer

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 15/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

/text Search the text text


N Search forward the next occurrence searched
$ Put cursor at the end of the line
^ Put cursor at the beginning of the line
:1 Put cursor at the line 1
:3 Put cursor at the line 3
G Put cursor at the last line
:w Save the file
:w filename Save the file to a new file name
:r filename Insert a file
:3,5m8 Move lines from 3 to 5 to the line 8
:3,5t8 Copy lines from 3 to 5 to the line 8
:q! Quit editor without saving

5. Create the file EjemploMenu.java with the following text. Comment the commands used.

/*
* EjemploMenu.java
*
* Obtenido del libro “Manual de Referencia Java 2, cuarta edición”,
* para el curso de Programación II.

* 16/05/2007
*/

// Utilizacion de un bucle do-while para procesar un menu de selección.


class EjemploMenu {
public static void main (String args [ ])
throws java.io.IOException {
char eleccion;

do {
System.out.println("Ayuda para:");
System.out.println(" 1. if");
System.out.println(" 2. switch");
System.out.println(" 3. while");
System.out.println(" 4. do-while");
System.out.println(" 5. for\n");
System.out.println("Elija una opcion:");
eleccion= (char) System.in.read();
} while ( eleccion < '1'||eleccion > '5');

System.out.println("\n");

switch(eleccion) {
case '1':
System.out.println("La sentencia if:\n");
System.out.println("if(condicion) sentencia;");
System.out.println("else sentencia;");
break;
case '2':
System.out.println("La sentencia switch:\n");

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 16/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

System.out.println("switch(expresion) {");
System.out.println("case constante:");
System.out.println("sucesion de sentencias");
System.out.println("break;");
System.out.println(" // ...");
System.out.println("}");
break;
case'3':
System.out.println("La sentencia while:\n");
System.out.println("while(condicion) sentencia;");
break;
case'4':
System.out.println("La sentencia do-while:\n");
System.out.println("do {");
System.out.println("sentencia;");
System.out.println("} while(condicion);");
break;
case '5':
System.out.println("La sentencia for:\n");
System.out.println("for(inicializacion; condicion; iteracion)");
System.out.println(" sentencia;");
break;
}
}
}

Module 6 - Using Commands within the Shell

Task summary and solutions

1. Use shell metacharacters: “*”, “?”, “[]”


a. In your home directory, create the following files in the tmp directory:

$cd
$cd tmp
$touch tmp
$touch tmpa
$touch tmpb
$touch tmpc
$touch tmpab
$touch tmpabc
$touch tmp123
$touch tmp345`[]
$touch tmp456
$touch tmp.123

b. Use the metacharacters with the ls command, practice with the following tasks.

$ls *a
$ls tmp?
$ls tmp[a-b]

c. What is the output of the following tasks?

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 17/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

$ls tmp*[3-5]?
$ls ??
$ls tmp??
$ls *3
$ls *.*

2. Describe the Bash (Bourne Advanced Shell) shell variables

$set
$set |more
$env
$env|more

3. Display the command history

$more .bash_history

4. Describe the command-line interpreter: bash


5. Work with user initialization files

a. Edit the .profile file


b. Add a line and use echo command
c. Add a line and see the content of a file

Module 7 - Using Basic File Permissions

Task summary and solutions

1. View file and directory permissions

$ls -l

2. Determine file or directory access


3. Rights rwx for the user, group and other. Symbolic and numeric format.
4. Change the permissions

a. Create the myrights file with the following contents, using the echo command and see the
permissions

Hello everybody
I am testing permissions

$echo “Hello everybody” > myrights


$echo “I am testing permissions” >> myrights
$ls -l

b. Change permissions in numeric format

chmod 544 myrights

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 18/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

$ls –l myrights

c. Try to edit it, what happened?

$echo “One more line” >> myrights


$vi myrights

In both cases, it can not be modified because permission to write is denied.

d. Create mynewdir directory and see the permissions.

$mkdir mynewdir
$ls –ld mynewdir

e. Change permissions in symbolic format

$chmod u-x mynewdir


$ls –ld myrights

f. Try to enter to it, what happened?

$cd mynewdir

It can not access because permission to search is denied.

5. Modify the default permissions: When you create a file or a directory as shown before, they have
default permissions. These permissions are modified only by the root user.

Module 8 - Configure Access Control Lists (ACLs)

Task summary and solutions

(Omitted)

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 19/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Searching and Process Manipulation

Module 9 - Searching Files and Directories

Task summary and solutions

1. Search for content in files: grep command

$grep Hernandez /etc/passwd


$grep “Hernandez Perez” /etc/passwd
$grep 04 /etc/passwd
$grep ^04 /etc/passwd
$set > setfile
$grep –i path setfile
$set|grep –i path
$set |grep –w path
$grep –iw path setfile
$rm setfile

2. Search for files and directories: find command

$find . –name tmpa*


$find /etc –name ftphosts
$find /etc –name ftphosts –exec ls –l {} \;

3. Create three files with hard links and see their i-node number

$echo “This is for testing find command with –I option” > testfind
$ln testfind testfind.lnk
$ln testfind.lnk testfind.link
$ls -li
$find . –inum 1032 –exec cat {} \;

Module 10 - Performing Basic Process Control

Task summary and solutions

1. Describe Solaris OS processes


2. View a process

a. Create the sleep process.

$sleep 6

b. Now, create three sleep processes but running in background.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 20/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

$sleep 60&
$sleep 60&
$sleep 60&

c. Run the bash shell twice.

$bash
$bash

d. View the processes

$ps

e. View the processes of the system.

$ps –ef
$prstat

3. Search for a specific process

$pgrep Xsun
$pgrep –fl Xsun
$pgrep –fl Xsesion

4. Send a signal to a process

a. Try to kill a process that not belongs to you, what happened?

$kill 1030

b. Now, kill processes that belong to you.

$kill 1020
$pkill sleep

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 21/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Working with the Shell

Module 11 - Advanced Shell Functionality

Task summary and solutions

1. In order to manage jobs in the Bash shell, comment what a job is and what is to schedule a job.
2. Schedule a job by practicing the following tasks:

a. Verify if environment variable EDITOR is assigned.

$echo $EDITOR

Or

$set |grep –iw editor

b. if it is not, assign the environment variable EDITOR to vi.

$EDITOR=vi

c. Export the variable EDITOR.

$export EDITOR

d. Verify the number of your terminal.

$tty
/dev/pts/4

e. Check the date.

$date

f. Use the at command to schedule a job, so the job execute 2 minutes later.

$at 12:03
>echo “This is my job running very good” > /dev/pts/4
CTRL-d

g. Wait the time arrived, so what happened?

Two minutes later, appeared the message in the monitor.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 22/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

3. In order to describe the Bash shell alias utility, it can comment that aliases are used to simplified a
complex commands. An alias is another way to name a command. You can add aliases in the
command line and they are present while the session is on. They are in .profile shell scripts to be
executed in connection time, while .profile is executed when bash shell start.
4. Practice alias command with the following tasks:

a. See the present aliases.

$alias

b. Create the next aliases.

$alias dir=’ls –la ’


$alias rename=’mv’
$alias thisuser=’grep rhp /etc/passwd’

c. Verify if they exist.

$alias

d. Use dir, rename and thisuser aliases.

$dir
$dir /
$dir /etc
$touch onefile
$ls –l onefile
$rename onefile one.file
$ls –l onefile
$ls –l one.file
$rm one.file
$thisuser

e. Delete dir alias and verify it is not exist.

$unalias dir
$alias

f. Delete all aliases.

$unalias -a

5. In order to use Bash shell functions, practice the following tasks:


6. In order to set Bash shell options, practice the following tasks:

Module 12 - Reading Shell Scripts

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 23/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Task summary and solutions

1. In order to describe shell scripts, comment what they are.


2. It is out of scope of this course to program shell scripts, even thought to read shell scripts it is
necessary to write them. It is shown some examples in order to know some characteristics such as:
run shell scripts, pass values to shell scripts, use the test command, and perform conditional
commands. All script shell files should have comments. The first line one is the shell where it runs,
the second is its name. The third is who belongs to, the fourth is a brief description and the last one
is its identification.

a. As a first example of a shell script, write script1 file with the following contents.

$vi script1
#!/bin/bash
#
# ~/script1
#
# Copyright 2007 by Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales.
#
# First example of a shell script.
# It executes simple commands.
#
# ident "@(#)script1 1.0 9/8/2007 Roberto H.P."

date “+%r”
cat phrase

b. Execute script1 shell script, what does it do?

$chmod u+x script1


$./script1

Just print the hour and the contents of the phrase file.

c. As a second example of a shell script, write script2 file with the following contents.

$vi script2
#!/bin/bash
#
# ~/script2
#
# Copyright 2007 by Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales.
#
# Second example of a shell script.
# Show messages and if the user decides, shows the contents of a file.
#
# ident "@(#)script2 1.0 9/8/2007 Roberto H.P."

clear
echo
echo "Welcome Roberto H.P. to Solaris 10"
echo

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 24/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

echo -n "You begin your session at "


date “+%r”
echo -n "Do you wish to see the today’s phrase? (y/n)"
read wish
if [ "$wish" = "y" ]; then
cat phrase
fi

d. Execute script2 shell script, what does it do?

$chmod u+x script2


$./script2

It does what the description says.

e. As a third example of a shell script, write script2a file with the following contents.

$vi script2a
#!/bin/bash
#
# ~/script2a
#
# Copyright 2007 by Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales.
#
# Third example of a shell script.
# Show messages and if the user decides, shows the contents of a file.
# Same script2 but use test command instead of [].
#
# ident "@(#)script2a 1.0 9/8/2007 Roberto H.P."

clear
echo
echo "Welcome Roberto H.P. to Solaris 10"
echo
echo -n "You begin your session at "
date “+%r”
echo -n "Do you wish to see the today’s phrase? (y/n)"
read wish
if test "$wish" = "s" ; then
cat phrase
fi

f. Execute script2a shell script, what does it do?

$chmod u+x script2a


$./script2a

It does what the description says.

g. As a fourth example of a shell script, write script3 file with the following contents.

$vi script3
#!/bin/bash

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 25/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

#
# ~/script3
#
# Copyright 2007 by Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales.
#
# Fourth example of a shell script.
# Use environment variables.
#
# ident "@(#)script3 1.0 9/8/2007 Roberto H.P."

clear
echo
echo "Welcome Roberto H.P. to Solaris 10"
echo
echo "Your are connected to $HOSTNAME host"
echo
echo "Your home is $HOME"
echo
echo -n "You begin your session at "
date “+%r”
echo -n "Do you wish to see the today’s phrase? (y/n)"
read wish
if [ "$wish" = "y" ]; then
cat phrase
fi

h. Execute script3 shell script, what does it do?

$chmod u+x script3


$./script3

It does what the description says.

i. As a fifth example of a shell script, write script4 file with the following contents.

$vi script4
#!/bin/bash
#
# ~/script4
#
# Copyright 2007 by Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales.
#
# Fifth example of a shell script.
# Use functions.
#
# ident "@(#)script4 1.0 9/8/2007 Roberto H.P."

# Press any key to continue.

Enter()
{
echo
echo -n "Press any key to continue ..."
read enter

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 26/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

# Press key “y” to continue.

Entery()
{
echo -n "Do you wish to see the today’s phrase? (y/n)"
read wish
}

# Main shell script

clear
echo
echo "Welcome Roberto H.P. to Solaris 10"
echo
echo "Your are connected to $HOSTNAME host"
Enter
echo "Your home is $HOME"
Enter
echo -n "You begin your session at "
date “+%r”
Entery
if [ "$wish" = "y" ]; then
cat phrase
fi

j. Execute script4 shell script, what does it do?

$chmod u+x script4


$./script4

It does what the description says.

k. As a sixth example of a shell script, write script5 file with the following contents.

$vi script5
#!/bin/bash
#
# ~/script4
#
# Copyright 2007 by Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales.
#
# Sixth example of a shell script.
# Use of arguments. It also uses the case structure.
# It can be run as "./script5" or "./script5 none" or "./script5 all".
#
# ident "@(#)script5 1.0 9/8/2007 Roberto H.P."

# Press any key to continue.

Enter()
{
echo

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 27/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

echo -n "Press any key to continue ..."


read enter
}

# Press key “y” to continue.

Entery()
{
echo -n "Do you wish to see the today’s phrase? (y/n)"
read wish
}

# Main shell script

case "$1" in
'all')
clear
echo
echo "Welcome Roberto H.P. to Solaris 10"
echo
echo "Your are connected to $HOSTNAME host"
Enter
echo "Your home is $HOME"
Enter
echo -n "You begin your session at "
date “+%r”
Entery
if [ "$wish" = "y" ]; then
cat phrase
fi
;;
'none')
clear
;;
*)
echo "Usage: $0 { all | none }"
exit 1
;;
esac
exit 0

l. Execute script5 shell script, what does it do?

$chmod u+x script5


$./script5

It does what the description says.

3. As a comparison in structure, compare script5 and /etc/rc3.d/S81volmgt shell scripts.

$cat /etc/rc3.d/S81volmgt
#!/sbin/sh
#
# Copyright 2004 Sun Microsystems, Inc. All rights reserved.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 28/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

# Use is subject to license terms.


#
# ident "@(#)volmgt 1.8 04/11/05 SMI"

case "$1" in
'start')
if [ -f /etc/vold.conf -a -f /usr/sbin/vold -a \
"${_INIT_ZONENAME:=`/sbin/zonename`}" = "global" ]; then
echo 'volume management starting.'
/usr/sbin/vold >/dev/msglog 2>&1 &
fi
;;

'stop')
/usr/bin/pkill -x -u 0 -z ${_INIT_ZONENAME:=`/sbin/zonename`} vold
;;

*)
echo "Usage: $0 { start | stop }"
exit 1
;;

esac
exit 0

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 29/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Archiving Files and Remote Transfer

Module 13 - Creating Archives

Task summary and solutions

1. In order to archive files, you should know what is an archive file, how to create it, see its contents
and deployed it so you can recover the original files. An archive file is a file that contains other files,
so you can manage only one and in that way you have many files in only one. You use the tar
command with different options to manage it.
2. Before archive files, let’s see the file types.

a. Check the script1 script shell file type, what type is it?

$file script1

This file is known as an executable.

b. Now, take care out the execution permission and check the type again, what type is it?
Restore its permissions.

$chmod u-x script1


$file script1
$chmod u+x script1

This file is also known as an executable even thought it has not executable permissions. It is
due to the first line contains #!/bin/bash.

c. Let’s try the same, but without the first line. Copy script1 file to script1.tmp file and delete
the first line of this last file. Execute it. Verify its type. Later take care out the executable
permissions, try to execute it. Last, verify its type. Is it run? What type is it in both cases?
Delete script.tmp file.

$cp script1 script.tmp


$vi script1.tmp

Put cursor in the first line, press d key twice, then save it and exit (ESC :wq).

$./script1.tmp
$file script1.tmp
$chmod u-x script1.tmp
$./script1.tmp
$file script1.tmp
$rm script1.tmp

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 30/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Yes, it runs good as script1 do, but the second time it is not, as it should be. In both cases,
the type is ascii.

Note: The file command is used to determine the type of a file. Possible types are ascii, directory, link,
executable, compress, zip and tar.

3. Take present the script shell files done before. Archive files.

a. Create the myscripts archive file with five script shell files

$tar -cvf myscripts script[1-5]

b. Check the file type of myscripts.

$file myscripts

c. Now, create the myscripts.tar archive file with all script shell files and check its type.

$tar –cvf myscripts.tar script*


$file myscripts.tar

d. What is the difference between myscripts and myscripts.tar.

Both are tar files, but myscripts.tar includes script3a.

Note: Tar files names used to end in “.tar”.

e. Now, verify the myscripts.tar file contains.

$tar –tvf myscripts.tar

f. Deploy myscripts.tar file in a new directory called dir.scripts and see the script1 file
contains.

$mkdir dir.scripts
$cp myscripts.tar dir.scripts
$cd dir.scripts
$tar –xvf myscripts.tar
$cat script1

g. Remove dir.scripts directory and its contains.

$cd
$rm –r dir.scripts

4. There is not exits compression and archive files altogether using the tar command. So first archive
files with tar and later compresses it with any utility. To compress files is shown next module.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 31/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

Module 14 - Compressing, Viewing, and Uncompressing Files

Task summary and solutions

1. One way to compress files is by using the compress command.

a. First, verify the size of script1 (done before) file then compress it with compress command.
Verify the name and the size.

$ls –l script1
$compress script1
$ls –l script1

Note: If you use compress command for compressing files, these ones end with .Z.

b. Verify the file type of script1.Z file.

$file script1.Z

2. In order to view compressed files, it is used the zcat command if the compressed file was done with
the compress command.

a. See the contents of script1.Z file.

$zcat script1.Z

3. Uncompress files using uncompress command for files compressed with compress command.

a. Uncompress the script1.Z file. Verify the name and the size.

$uncompress script1.Z
$ls –l script1*

4. Another way to compress a file is with the gzip command.

a. First, verify the size of script1 (done before) file then compress it with gzip command.
Verify the name and the size.

$ls –l script1
$gzip script1
$ls –l script1*

Note: If you use gzip command for compressing files, these ones end with .gz.

b. Verify the file type of script1.gz file.

$file script1.gz

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 32/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

5. In order to view compressed files, it is used the gzcat command if the compressed file was done
with the gzip command.

a. See the contents of script1.gz file.

$gzcat script1.gz

6. Uncompress files using gunzip command for files compressed with gzip command.

a. Uncompress the script1.gz file. Verify the name and the size.

$gunzip script1.gz
$ls –l script1*

7. Compress and archive multiple files with the zip command.

(Pending)

Module 15 - Performing Remote Connections and File Transfers

Task summary and solutions

1. In order to establish a remote login session, you need to be in a login session. Once you have a login
session, you can connect to another system by a remote login session with rlogin command. (it can
also use telnet command as you did it in Module 1).

a. Logging to system 192.168.254.54, use guest as user name and 123pass as password.

$rlogin 192.168.254.54

b. Can you see your files, why?

$ls –l

No, I can not see my files because in this session (window, I am connected to another
system, but the desk top is mine.

2. In order to copy files or directories to and from another system, it is necessary that a file system or
part of it, be mounted in one of them.

a. Previously, the administrator have mounted the /Blade2 file system into /Blade2 directory.
b. Change to the /Blade2 directory, where are you?, what files you see?

$cd /Blade2
$pwd
$ls –l

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 33/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

I am in /Blade2 directory, and there is nothing files. But in reality, I am listing files on
another (Blade2) system.

c. Make a directory, its named will be as your logging name, for instance, 285.

$mkdir 285

d. Now, change to your home directory and copy your script files (done before) to
/Blade2/285 directory. Verify that it is done.

$cd
$cp script* /Blade2/285
$ls –l
$cd /Blade2/285
$ls –l

Note: It is the same to do $cd /Blade2/285 and $ls –l that $ls –l /Blade2/285. The difference is that you do
not change working directory.

e. Now, change to your home directory and copy your tmp directory and its contents to
/Blade2/285 directory. Verify that it is done.

$cd
$cp –r tmp /Blade2/285
$ls –l tmp
$ls –l /Blade2/285/tmp

f. Where are your files and directories in reality?

The copied files and directories are in another (Blade2) system.

g. In your home directory, delete script1 file.

$cd
$rm script1
$ls –l script1

h. Copy from /Blade2/285 directory this file to your home again. Verify that it is your home.

$cp /Blade2/285/script1 .
$ls –l script1

i. Delete /Blade2/285/tmp directory.

$rm –r /Blade2/285/tmp

j. What can you do with files and directories in /Blade2/285 directory

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 34/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

I can manage files and directories as if they were in my system. They are in another system.
It can be done because the administrator gave the permissions.

k. Change to your home directory and as your administrator to unmount the /Blade2 file
system.

$cd

l. Change to the /Blade2 directory, where are you? What files do you see? Where are your
files?

$cd /Blade2
$pwd
$ls –l

I am in /Blade2 directory, and there is nothing files. But now, I am listing files on my own
(Blade1) system. My files remain in another (Blade2) system.

3. Another way to copy files to and from another system is transferring files between systems by using
ftp command. Transferring files can be done between heterogeneous systems, so you can copy a
file from a Solaris system to a Windows one and vice versa. First, transfer files between Solaris
systems.

a. Make a connection to Blade2 (192.168.254.54) system using ftp command, use guest as a
user name and 123pass as password.

$ftp 192.168.254.54

b. Can you see your files, why?

ftp>ls

No, I can not see my files because I am connected to another (Blade2) system by ftp
protocol.

c. Make a directory, its named will be as your logging name, for instance, 285.

ftp>mkdir 285

Note: The 285 directory was created in Blade2 system and it is located in the guest user home directory.

d. Now, change to this directory and copy (transfer or put) your script1 file (done before) to
285 directory. Verify that it is done.

ftp>cd 285
ftp>put script1
ftp>ls

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 35/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

e. Now, Transfer or put your script3 and script3a files (done before), answer “y” for each
question. Verify that it is done.

ftp>mput script3*
ftp>ls

Note: You use “put” to transfer a file from your system to the other one. You use “mput” to transfers
multiple files. In order to get a file or multiple files from the other system to your system, you must use
“get” and “mget” respectively.

f. Where are your files in reality?

The copied files are in another (Blade2) system.

g. Now, open a new terminal window with a CLI and in your home directory, delete script1
file.

$cd
$rm script1
$ls –l script1

h. Change to the ftp connection and get a copy of the script1 file.

ftp>get script1

i. Verify that it is your home. Change to your terminal window.

$ls –l script1

j. Exit from your ftp connection.

ftp>bye

4. Last, transfer files between Solaris and Windows systems.

a. In your Windows system, open an MS-DOS Console and change to a directory where you
have permissions to write files. For this practice, it will be use the c:\tmp directory.
b. Make a connection to Blade1 (192.168.254.53) system using ftp command, use your login
name as user name and your password.

C:/tmp>ftp 192.168.254.53

c. Can you see your files, why?

ftp>ls

Yes, I can see them because I am connected to my (Blade1) systems from another
(Windows) system by ftp protocol.

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 36/37
UNIX Essentials Featuring the Solaris 10 Operating System: Exercises

d. Now, copy (transfer or get) your script1 file (done before) to your c:\tmp directory
windows system.

ftp>get script1

e. In order to verify that it is done, in your Windows system, use any Windows Utility and
observe the c:\tmp directory.
f. Now, Transfer or get your script3 and script3a files (done before), answer “y” for each
question.

ftp>mget script3*

g. In order to verify that it is done, In your Windows system, use any Windows Utility and
observe the c:\tmp directory.
h. Where are your copied files in reality?

The copied files are in my Windows system.

i. Now, open a new terminal window with a CLI in you Solaris system and in your home
directory, delete script1 file.

$cd
$rm script1
$ls –l script1

j. Change to the ftp connection in your Windows system and put a copy of the script1 file to
Solaris system.

ftp>put script1

k. Verify that it is your home directory in Solaris system. Change to your terminal window.

$ls –l script1

l. Exit from your ftp connection.

ftp>bye

Instituto Tecnológico de Pachuca. Academia de Ciencias Computacionales. Roberto Hernández Pérez. Agosto 2007. Page 37/37

Вам также может понравиться