Vous êtes sur la page 1sur 42

1 Logging into SunOS

1.1 Logging in
When no one is “logged in”, a welcome window is displayed as:

Schlumberger Private
• Enter the username name given to you by the system administrator or your instructor and
press the “Enter” key on the keyboard.

• The system will request you to enter the password as shown above.
Enter the password, provided to you by the system administrator or your instructor, in the
space, as shown in the illustration above and press Enter. (If your account does not have a
password assigned to it, the system logs you without asking you for password).
Note: the system does not display (echo) your password on the screen as you type it. This is to
prevent others from discovering your password.

1
1.2 How to open a terminal window
A terminal window is a window in which you can work in command line mode of Unix. To
open an XTerminal window, click on the right button of the mouse (MB3). A scroll menu
will appear. Choose the “Programs” submenu, then select: “Terminal…” (MB3 > Programs
> Terminal).

1.3 How to close a terminal window


When you have finished working with a terminal window you can close it by typing the exit
command followed by pressing the enter key on your keyboard.

Schlumberger Private
1.4 Logging out
When you finish your work session and are ready to exit the operating system, click on the
right button of the mouse, you’ll obtain a menu. Choose the “Log out…” option in order to
log out of the system. The system will ask you for a confirmation, click OK.
After a moment, the system once again displays the Welcome window indicating that you
successfully logged out. The system is now ready for you or another user to log in.

2 Working with files and directories


The file is the basic unit in the SunOS operating system. Almost everything is treated as a file,
including:
• Documents: These include text files, such as letters or reports, computer source code, or
anything else that you write and want to save.
• Commands: Most commands are executable files; that is they are files you can execute to
run a particular program. For example, the date command, which provides the current
time and date, is an executable file.
• Devices: Your terminal, printer and disk drive(s) are all treated as files.
• Directories: A directory is simply a file that contains other files.

The following section explains the commands available for creating, listing, copying, moving
and deleting files. You’ll also see how to list the contents of a file and how to determine the
nature of a file.

2
2.1 Using File commands

2.1.1 Before you begin


Before you start experimenting with files, make sure that you are in your home directory. This
is a directory established for you by the system administrator when your account was created.
If you perform tasks shown in the following examples from your home directory, you’ll be
less likely to create, copy, move or delete files within portions of the system that other users
expect to remain unchanged.
> cd

Schlumberger Private
> pwd
/diske/student5

In this example, the user’s home directory is /diske/student5, where “student5” is the name of
the user owning the home directory.

2.1.2 Creating a test file


Use the touch command to create an empty file.
If a file by the name you specify doesn’t already exist, the touch command creates an empty
file (if this file already exists, touch updates the last access time).
> touch tempfile

2.1.3 Listing files (ls)


Now list the file with the ls command:
> ls tempfile
tempfile

3
2.1.4 Copying files (cp)
Use the cp command to copy tempfile to a file called copyfile
> cp tempfile copyfile

If you now want to list the contents of the directory, the command ls *file should list both
tempfile and copyfile (and any other file in this directory with a name that end with file).
> ls *file
copyfile tempfile

Schlumberger Private
2.1.5 Moving and renaming files (mv)
You can both move and rename files using the same command, mv (move). In this example,
use the mv command to rename tempfile to emptyfile:
> mv tempfile emptyfile

Now list both files again to verify the change:


> ls *file
copyfile emptyfile

As you can see, tempfile is replaced by emptyfile.

2.1.6 Deleting files (rm)


Finally, use rm (remove) command to delete copy file, and verify the result with the ls
command:
> rm copyfile
> ls *file
emptyfile

Note: Deletes files cannot be restored unless you have a backup containing the original files.

4
2.1.7 Displaying file contents (more, cat)
Use the more command to display the contents of a file. Type more followed by the name of
the file to be displayed. The contents of the file scrolls down the screen. If the file is longer
than one screen, this message appears:
--More—(nn%) [Press space to continue, ‘q’ to quit. ]

Where nn is the percentage of the file already displayed.


You can also use the cat command to display the contents of a file.

Schlumberger Private
2.1.8 Displaying file type (file)
Use the file command to show the file type:
> file emptyfile
emptyfile: ascii text

2.1.9 Directories and hierarchy


By now you know how to list, copy, rename and delete files. However, you may be
wondering about larger issues. Where are these files located? This section discusses the
directory hierarchy. Read the following narrative carefully and then try the examples in the
sections that follow.

2.1.10 Directory hierarchy


Files are grouped into directories which are them selves organized in a hierarchy. At the top
of the hierarchy is the “root” directory, symbolized by “/”

/ (Root)

/usr opt /diske /var

5
2.1.11 Print working directory
The command pwd (print working directory) tells you your current directory:
> pwd
/diske/student5

2.1.12 Change working directory (cd)


The cd (change directory) command allows you to move around within the file system
hierarchy:

Schlumberger Private
> cd /usr/lib
> pwd
/usr/lib

When you type the cd command by itself, you return to your home directory. For example, if
your home directory was /diske/student5:
> cd
> pwd
/diske/student5

In the C shell, the tilde (~) is used as shortcut for specifying your home directory. For
example, you would type the following to change the subdirectory music within your home
directory:
> cd ~/music

You can also use this shortcut to specify another user’s home directory. For example:
> cd ~username

Where username is another user’s login name, would change to that user’s home directory.

6
2.1.13 Creating directory (mkdir)
It is easy to create a new directory. Type the mkdir command followed by the name of the
new directory:
> mkdir data
> cd data
> mkdir geoframe
> cd geoframe
> pwd
/diske/student5/data/geoframe

Schlumberger Private
2.1.14 Moving and renaming directories
You rename a directory by moving it to a different name. Use the mv command to rename
directories:
> pwd
/diske/student5/data
> ls
geoframe
> mv geoframe eclipse
> ls
eclipse

You can also move a directory to a location within another directory:


> pwd
/diske/student5/data
> ls
eclipse
> mv eclipse ../data1
> ls ../data1
eclipse

In this example, the directory eclipse is moved from data to data1 with the mv command.

7
2.1.15 Copying directories
Use the cp –r command to copy directories and the files they contain:
> cp –r data data2

This command copy all file and subdirectories within the directory data to a new directory
data2. This is a recursive copy, as designated by the –r option. If you attempt to copy a
directory without using this option, you will see an error message.

2.1.16 Removing directories (rmdir)

Schlumberger Private
To remove a directory, use the rmdir command as follow:
> rmdir data2

if the directory still contains files or subdirectories, the rmdir command will not remove the
directory.
The rm –r (adding the recursive option –r to the rm command) to remove a directory and all
its contents, including any subdirectories and their files, as follow:
> rm –r data2

Caution: Directories removed with the rmdir command cannot be recovered, nor can
directories and their contents removed with the rm –r command.

2.1.17 Looking files (find)


The find command searches for files that meet conditions you specify, starting from a
directory you name. For example, you might search for filenames that match a certain pattern
or that have been modified within a specified time frame.
For example to see which files within the current directory and its subdirectories begin with
data
> pwd
/diske/student5
> find . –name “data*” –print
./data
./data1

8
Other options include:
- name filename
Selects files whose rightmost component matches filename.
-user userid
Selects files owned by userid. userid can be either a login name or a user ID number
- group group
Selects files belonging to group
- m time n
Selects files that have been modified within n days

Schlumberger Private
2.1.18 File and directory security
These are the basic file and directory permission type:
• r: read permission. A file must be readable to be examined or copied. A directory must be
readable for you to list its contents.
• w: Write permission. A file must be writable in order for you to modify it, remove it or
rename it. A directory must be writable for you add or delete files in it.
• x: Execute permission: A file with executable permissions is one you can run, such as
program. A directory must be executable for you to gain access to any of its
subdirectories.

There are 3 categories of users for which you can set permissions:
• Self: the user
• Group: Other users within the same group as the user (for example, all accounting users).
Groups are established and maintained by the system administrator.
• Others: Everyone else

2.1.19 Displaying permission and status (ls –l)


You have already use the ls command to list files. The ls command has many options. Use the
–l option to display a long format list. Files and directories are listed in alphabetical order.
The following figure illustrates this method for displaying files:
> pwd

9
/diske/student5
> ls –l
total 8
drwxr--r-- 2 student5 1024 Jan 7 11:45 data
drwxr--r-- 2 student5 1024 Jan 7 12:30 data1
-rw-r--r-- 2 student5 0 Jan 7 11:30 emptyfile
Permissions Links Owner Size Date Time File or directory name

The first character on the line indicates the file type. A “-“ (hyphen) is an ordinary file;

Schlumberger Private
d indicates a directory, and other characters indicate other special file types.
The next nine characters indicate the permissions of the file or directory. The nine characters
consist of three groups of three, showing the permissions for owner, the owner’s group and
the world, respectively. The permissions for emptyfile are rw-r- -r- -, indicating that the
owner can read and write this file, everyone can read it and no one can execute it. The
permission for directory data1 are rwxr-xr-x, indicating that everyone has read and execute
permissions, but only the owner can write to it.
In addition to file permissions, the display shows the following information:
• Number of links to this file or directory
• Name of the owner (student5 in this case)
• Number of bytes (characters) in the file
• Date and time the file or directory was updated
• Name of the file or directory

10
2.1.20 Listing hidden files (ls –a)
There are some files that are not listed by the ordinary ls command. These files haves names
beginning with the character . (called “dot”), such as “.cshrc”, “.login”, “.profile”. Use the
ls –a command to list these files:
> ls –a
.
..
.cshrc
.login

Schlumberger Private
.profile
emptyfile

Notice that the files beginning with “ .” are listed before the other files. There are two special

files in this listing: the file “ .” is the reference for the current directory, and the file “ ..” is
the reference for the parent directory.

2.1.21 Changing permissions (chmod)


Use the chmod command to change permissions for a file or a directory. You must be the
owner of a file or a directory, or have root access to change its permissions. The general form
of the chmod command is:
> chmod permissions filename

Where permissions indicates the permissions to be changed and filename is the name of the
affected file or directory.
The permissions can be specified in several ways. Here is one of the forms which is easiest to
use:
1. Use one or more letters indicating the users involved:
• u (for the user)
• g (for the group of users)
• o (for other users)
• a (for all three or above categories)

11
2. Indicate whether the permissions are to be added (+) or removed (-).
3. Use one or more letters indicating the permissions involved.
• r (for read)
• w (for write)
• x (for execute)
In the following example, write permission is added to the directory
> ls –l eclipse
drwxr-xr-x 3 student5 1024 Jan 7 11:30 eclipse
> chmod g+w eclipse

Schlumberger Private
> ls –l eclipse
drwxrwxr-x 3 student5 1024 Jan 7 11:30 eclipse

As you can see, the hyphen (-) in the set of characters for group is changed to a w as a result
of this command.

To make this directory non-readable and non-executable by the other users outside your group
(permissions is o-rx), you would enter the following:
> ls –l eclipse
drwxrwxr-x 3 student5 1024 Jan 7 11:30 eclipse
> chmod o-rx eclipse
> ls –l eclipse
drwxrwx--- 3 student5 1024 Jan 7 11:30 eclipse

Now, the r (for read) and the x (for execute) in the set of characters for others users are both
changed into hyphens.

When you create a new file or directory, the system automatically assigns permissions. In
general the default settings for a file are: -rw-r --r--
And for new directories are: drwxr-xr-x

12
So, to make a new file test executable by its owner (student5), you would enter the following:
> ls –l test
-rw-r--r-- 3 student5 1024 Jan 7 11:30 test
> chmod u+x test
> ls -l
-rwxr--r-- 3 student5 1024 Jan 7 11:30 test

2.1.22 Setting absolute permissions

Schlumberger Private
Up to this point, the discussion on permissions has only included using the chmod command
to change permissions relative to their current settings. Using a different form of the chmod
command, which applies numeric codes to specify permissions, you can set the permissions
for a file or directory absolutely.
The syntax for this usage of chmod command is:

chmod numcode name

Where numcode is the numeric code and name is the name of file or directory for which you
are changing permissions.
The complete numeric code consists of three numbers. One number is used for each of the
three categories: user, group and other. For example, the following command sets absolute
read, write and execute permissions for the user and the group, and execute permissions only
for others:
> chmod 771 test

The following table illustrates how the permissions described for test are represented by the
code 7 7 1.
Permissions for test
Permission User Group Others
Read 4 4 0
Write 2 2 0
Execute 1 1 1
Total 7 7 1

13
The following is another example of this method for setting absolute permissions, with the
ls –l command to demonstrate the results:
> ls –l test1
-rw-r--r-- 3 student5 1024 Jan 7 11:30 test1
> chmod 755 test1
> ls –l test1
-rwxr-xr-x 3 student5 1024 Jan 7 11:30 test1

Schlumberger Private
3 Searching files

3.1 Searching for patterns with grep


To search for a particular character string in a file, use the grep command.
The basic syntax of the grep command is:
> grep string file

Where string is the word or phrase you want to find, and file is the file to be searched.
For example, to find the phone number of the user student4 (this information is stored in the
test file)
> grep student5 test
student5 021 656666

Note that more than one line may match the pattern you give:
> grep student test
student1 021 616666
student2 021 626666
student3 021 636666
student4 021 646666
student5 021 656666

grep is case-sensitive; that is, you must match the pattern with respect to uppercase and
lowercase letters:

14
3.1.1 Filtering using “grep”
The following example displays files ending in “.tmp” that were created in the month of May:
> ls –l *.tmp |grep May

the first part of this command produces a list of files:


> ls –l *.tmp
-rw-r--r-- 1 student5 1567 Apr 15:07 change.tmp
-rw-r--r-- 1 student5 2356 May 16:05 clock.tmp
-rw-r--r-- 1 student5 1567 May 16:15 cmdtool.tmp

Schlumberger Private
-rw-r--r-- 1 student5 1067 Apr 12:45 commandos.tmp

the second part, “|grep May” pipes that list through grep, looking for the pattern May:
> ls –l *.tmp | grep May
-rw-r--r-- 1 student5 2356 May 16:05 clock.tmp
-rw-r--r-- 1 student5 1567 May 16:15 cmdtool.tmp

3.1.2 “grep” with multi-word strings


To find a pattern that is more than one word long, enclose the string with single or double
quotation marks:
> grep “021 61” test
student1 021 616666

grep can search for a string in a group of files. When it finds a pattern that matches in more
than one file, it prints the name of the file, followed by a colon, then the line matching the
pattern:
> grep student5 *
test: student5 021 616666
test1:student5 Malika

15
4 Print command
This section presents the most common print commands.

4.1 How to submit a job (a file)


Use the command lp to submit a specified file (usually, we call it job) to a printer as follows:
lp –d printer_name file_name
Where:
printer_name: is the name of the printer you want to print on (if you don’t know it, ask your
system administrator).

Schlumberger Private
file_name: is the name of the file you want to print.
Example:
> lp –d hp4mv test
request id is hp4mv-408 (1 file(s))

Here we submitted the file test to the hp4mv printer.


hp4mv-408 is the identifier of the print job
Note: if you use the lp command without the “-d” option (just lp file_name), the file you
want to print will be send to the default printer.

4.2 How to show the status of a print job


Use the lpstat command in order to check the status of your print job as follows:
> lpstat
hp4mv-408 berkine!student5 2001 Jan 7 11:45

And use lpstat –o all in order to check the status of all print jobs (all users) as follows:
> lpstat –o all
hp4mv-408 berkine!student5 2001 Jan 7 11:45
hp4mv-409 berkine!root 2001 Jan 7 11:46

16
4.3 How to cancel a print job
Use the cancel command in order to cancel a job as follows:
> cancel hp4mv-408

Where: hp4mv-408 is the request ID of the file you want to cancel (here it is the id of the file
test)

5 Passwords, processes, and disk storage

Schlumberger Private
5.1 Using a password
When choosing a password, keep the following in mind:
• Choose a password that you can remember without writing it down. A password that you
can’t remember is worse than one that is too easily guessed.
• Choose a password that is at least six characters long and contains at least one number.
• Don’t use your own name or initials or name or initials of your spouse.
• Don’t use the names or pets or objects common to your interests.
• Don’t use all capital letters

5.1.1 Changing your password


To change your personal password, type the passwd command:
> passwd
Changing password for student5 on ainsalah
Old password:
New password:
Retype new password:
>

1. When the system prompts you for old password, type your current password.
If no password is currently assigned to your account, the system will skip the old password
prompt. Note that the system does not echo your password on the screen. This prevents other
users front discovering your password.

17
2. When the system prompts you for new password, type the password you’ve decided on.
Again the password you type does not echo on the screen.
3. At the final prompt, Retype new password:, type your new password second time. This is
to verify that you typed exactly what you intended to type.

5.2 Processes and PIDs


After each command is interpreted by the system, an independent process with a unique
process identification number PID, is created to perform the command. The system uses the
PID to track the current status of each process.

Schlumberger Private
5.2.1 Terminating processes using “kill”
The kill command provides you a direct way to stop command processes that you no longer
want. This is particularly useful when you make a mistake typing a command that takes a long
time to run.
To terminate a process:
1. Type ps to find out the PID(s) for the process(es).
2. Type kill followed by the PID(s).

the following example illustrates this procedure:


> ps
PID TTY TIME co
1291 co 0:12 -bin/csh (csh)
3250 PO 0:00 ps
1286 p1 0:05 -bin/csh (csh)
3248 p1 0:05 vi commands
> kill 1291
(1) Terminated -bin/csh (csh)

Note that a faster way of determining the right PID is to pipe ps output through grep as
follow:
> ps | grep commandname

18
Where commandname is the name of the command process you want to stop.
If you need to forcibly terminate a process, you can use the –9 option with the kill command
as follow:
> kill –9 PID

Where PID is the process identification number of the process you want to terminate (kill).

5.3 Managing disk storage

Schlumberger Private
5.3.1 Displaying disk usage “df –k”
df –k shows you the amount of space currently in use on each disk that is mounted (directly
accessible) to your system. Just type:
> df -k

to see the capacity of each disk mounted on your system, the amount available and the
percentage of space already in use.
N.B. File systems at or above 90 percent should be cleared of unnecessary files. You can do
this either by moving them to a disk or a tape that is less full, using cp to copy them and rm to
remove them, or you can simply remove them outright. Of course, you should only perform
these housekeeping tasks on files that you own.

5.3.2 Displaying directory usage (du)


You can use du –k to display the usage of a directory and all its subdirectories in K-byte.

19
6 Handling tape devices
In the following, we will user /dev/rmt/0 as the tape device path, but you should ask your
system administrator in order to obtain the device path corresponding to the tape drive you
want to use.

6.1 The mt command


The mt command sets control over the tape device mentioned, it comes with a variety of
qualifiers that enable full handling of the tape. In what follows, we give some examples:
0 Meaning automatic rewind to beginning of tape

Schlumberger Private
0l Meaning low density (2GB) writing to the tape
0m Meaning medium density (5GB) writing to the tape
0h Meaning high density (7GB) writing to the tape
0u Meaning compressed (10GB if 120m tape; 14 GB if 160m tape length)
0n Meaning no automatic rewind
0b Meaning to follow Berkley standard for EOT (end of tape)
Marker and EOF (end of file) marker assuming our tape device is
/dev/rmt/0

6.1.1 Rewinding a tape (using rew qualifier)

> mt –f /dev/rmt/0 rew

This rewind the tape to its beginning.

6.1.2 Forwarding a tape “n” files (using fsf qualifier)

> mt –f /dev/rmt/0n fsf 3

This forwards the tape 3 files ahead and stops at the beginning of the 4th file. It is useful in
dealing with tapes containing multiple files.
Note: The n for no rewind was important here so that the tape does not auto rewind to the
beginning of the tape after skipping the 3 files.

6.1.3 Checking a tape drive status (using stat qualifier)

> mt –f /dev/rmt/0 stat

20
This gives the current status of the tape drive.

6.1.4 Rewinding and ejecting a tape (using rewoffl qualifier)

> mt –f /dev/rmt/0 rewoffl

This brings the tape to its beginning and ejects it.

Schlumberger Private
6.2 Backup using “tar” command
To create a backup file on a tape of a directory or a file we use the tar command as follows:
tar cvf /dev/rmt/0 directoy_name
Or
tar cvf /dev/rmt/0 file_name
Also you can have several files or directories or a mixture between both by mentioning this in
the command line as follows:
tar cvf /dev/rmt/0 directory_name1 [file_name1]….[directory_name4]
Note: It is better to go to the location of the file or directory which is to be backed-up rather
than mentioning the full pathname for that file or directory; because if mentioned the
pathname you will be obliged whenever you restore your backed data that this location exists,
and you will be limited to just restoring to this location.

6.3 Listing a backup file


To list a backup file on the tape, we use the tar command as follow:
tar tvf /dev/rmt/0
This gives a listing of what resides on the tape.

6.4 Restore a backup file


To restore a backup file, we use the tar command as follows:
tar xvf /dev/rmt/0 file_name

21
to restore a specific file from a tape
tar xvf /dev/rmt/0
to restore the whole backup file from the tape

7 Some useful unix commands

7.1 The tcopy command


This is the tape copy command used to copy the whole tape contents to another tape or to a
disk regardless of its contents format, it is used as follows:

Schlumberger Private
tcopy source destination

For example: tcopy /dev/rmt/0 /dev/rmt/1


This copies the tape in drive /dev/rmt/0 to another tape in /dev/rmt/1
Also: tcopy /dev/rmt/0 file_name
Copies the tape contents to a file on the disk with the name file_name

Note: The file file_name must exist, this could be done by using the touch command to create
a file even if a zero-size file as previously mentioned:
touch file_name

7.2 The dd command


It copies a specified input file to a specified output file with the applied conversions. It reads
block by block from the input with the specified size and outputs it with the mentioned block
size.
For example:
dd if=/dev/rmt/0 of=/dev/rmt/1
Where if is the input file and of the output file.
Also:
tar cvf -.|compress|dd obs=1024k of=/dev/rmt/0
This tars the current directory then compresses it and outputs it to the tape with output block
size of 1024 K bytes.

22
7.3 The wc command
This acts as a counter command, it gives counts for words, characters and lines in the
specified file, for example:
wc –w file_name gives the number of words in the specified file
wc –l file_name gives the number of lines for the specified file
wc –c file_name gives the number of characters in the specified file

Schlumberger Private
7.4 The cut command
This cuts out selected fields of each line in the file. For example, if we have the file employee
as follows:
> cat employee
Name: Job_title:Salary:Location
Tom:Engineer:3500:Egypt
John:Accountant:4000:Italy
Henry:Manager:5000:Germany
Terry:Technician:2500:France

Then we want to get only the employee_name & location we can apply:
> cut –d: -f1,4 employee
Name: Location
Tom: Egypt
John: Italy
Henry: Germany
Terry: France

Here we mentioned that our delimiter is a colon “-d:”, and we want only first and fourth fields
“f1,4”.

We can also specify a range of characters where we want to apply the cut command for
example:
> cut –c1-20 employee

23
Name:Job_title:Salar
Tom:Engineer:3500:Eg
John:Accountant:4000
Henry:Manager:5000:G
Terry:Technician:250

Here we mentioned that we wanted the first 20 characters out of every line.

7.5 The xwd & xwud commands

Schlumberger Private
The xwd command enables us to capture a screen dump of an active window on a file like
follows:
xwd > file_name
A pointer like “+” will show. You should use this pointer to point to the window that you
would like to have a captures image of on the file file_name and then apply one click with
your left mouse button. You will hear one peep followed by 2 peeps to indicates that
capturing the image has been done.
To see how the captures image look like, you can apply the xwud command like this:
xwud < file_name
An image of the captured window will show. To remove it, click the left mouse button one
click.

24
8 Basic network commands

8.1 Objectives
Upon completion of this lesson, you’ll be able to:
• Describe the terms client-server and distributed processing
• Execute a command on another machine.
• Copy files from one machine to another machine
• Log in to another machine on the network

Schlumberger Private
• Work into a remote machine.
• Perform a backup into a remote tape drive.

8.2 Client-server

8.2.1 Distributed processing


Distributed processing allows access to remote system for the purpose of sharing information
and network resources, and it allows communication with users on other systems.

8.2.2 Server
A server is a machine that provides resources to one or more clients. A server connects to the
clients it serves by a network.

8.2.3 Client
A client is a machine that uses the services from one or more servers on a network.

8.2.4 Network
A network is a connection between machines that allows an exchange of information between
these machines. Three types of network are:
Local area network (LAN)
A LAN is a network that covers a small area, usually less than a few thousand feet.
Metropolitan area network (MAN)
A MAN is a network that can span across a city
Wide area network (Wan)
A WAN is a network that can span thousand of miles

25
8.3 The /etc/hosts file
Before using any network resource, you should know that for each entity connected to the
network corresponds an IP address. The /etc/hosts file contains these correspondences (you
can view it by typing the following command “pg /etc/hosts”)

8.4 The rsh command


Use the rsh (remote shell) command to execute a command on another machine.

Schlumberger Private
Command format:
rsh hostname [command]

Example:
Use the rsh command to look for specific information on another host rather than remotely
logging in to look for it.

> rsh berkine ls –l /tmp

8.5 Using the ftp command


Use the ftp command to copy a file or files to and from another machine.

8.5.1 Copying file(s) to another machine


In order to copy file(s) from your machine to another machine, follow these instructions:
1. Change to the directory from which you want to copy file(s).
2. Execute the command “ftp remote_name”, where remote_name is the name of the remote
machine you want to copy file(s) on. The system will ask you to enter the username and
the password you want to connect with (you must have an account in the host machine in
order to execute this command).
3. Change to the directory you want to copy on (cd directory_name)
4. Execute the command “put file_name”, where file_name is the name of the file you want
to copy

26
5. Once the file is copied (after the message of success), type “bye” in order to close the ftp
session
Note: If you want to copy more than one file you should replace the 4 th instruction by the
following:
mput file_name1 file_name2….
Or: mput *
And then, the system will ask you to choose the files you want to copy.

8.5.2 Getting file(s) from another machine

Schlumberger Private
In order to copy file(s) from another machine to your machine, follow these instructions:
1. Change to the directory to which you want to copy file(s).
2. Execute the command “ftp remote_name”, where remote_name is the name of the remote
machine you want to copy file(s) on. The system will ask you to enter the username and
the password you want to connect with.
3. Change to the directory you want to copy from (cd directory_name)
4. Execute the command “get file_name”, where file_name is the name of the file you want
to copy
5. Once the file is copied (after the message of success), type “bye” in order to close the ftp
session
Note: If you want to copy more than one file you should replace the 4th instruction by the
following:
mget file_name1 file_name2….
Or: mget *
And then, the system will ask you to choose the files you want to copy.

Note: When users copy files between systems, the files retain the ownership of the UID who
executed the command.

27
8.6 Log in to another machine
Before attempting to remotely log in to another system as a different user, be sure you have an
account on the remote machine you want to access. If not, check with your system
administrator.
The pertinent information is:
• Machine name
• Login ID
• Password
Remotely logging into workstation is helpful under the following circumstances:

Schlumberger Private
• To access information on another workstation that not available otherwise.
• To access your workstation to read mail
• To access your workstation to kill a process that has caused it to hang.

8.6.1 Using the rlogin command


Use the rlogin command to establish a remote login session on another workstation.
Command format:
rlogin hostname [-option]

Example:
Use rlogin command to establish a remote session on “berkine” the remote machine, with
your current login ID on your current local workstation.

> rlogin berkine


Password:
Last login Sat 6 16:00 berkine
Sun Microsystems Inc Solaris Generic Sept…

Use the “rlogin –l” to specify a different login ID for your remote login session.
Command format:
rlogin machinename -l username

28
Example:
> rlogin berkine -l user5
Password:
Last login Sat 6 16:00 berkine
Sun Microsystems Inc. SunOs 5.6 Generic august 1997
You have a new mail

8.6.2 Using the telnet command

Schlumberger Private
Use the telnet command to start a new login session to a remote machine with the login id you
specify at the “Login” prompt.
Command format:
telnet machinename

Example:
> telnet berkine
Login: user5
Password:
Last login Sat 6 16:00 berkine
Sun Microsystems Inc. SunOs 5.6 Generic August 1997
You have a new mail

8.7 Working in a remote machine


Here is the sequence of commands you should use in order to work in a server via your
workstation.
• With the right button of your mouse, click on the SunOs desktop. You’ll obtain a menu,
choose the “xhost +” option.
• Connect to this server with a telnet or rlogin command.
• Once you are connected, execute the following command:
setenv DISPLAY IP_address:0.0 or setenv DISPLAY hostname:0.0
Where IP_address: is the IP address of your local machine.
And hostname: is the hostname (name) of the workstation.

29
8.8 Using a remote tape drive
When having a network, this gives variety of benefits. One of which is using resources on
remote networked machines like in our case here the tape drive.
Consider having two machines:
“local” the current machine we are using
“remote” the remote machine with tape drive “/dev/rmt/0”

8.8.1 Baking up to a remote tape

Schlumberger Private
This could be done using the rsh command like this:

tar cvf – file_name | rsh remote dd of=/dev/rmt/0 obs=20b

Where obs is the output block size; we chose 20b because this is the standard default when
making a tar on a tape drive.

8.8.2 Restoring from a remote tape


This could be done like follows:

rsh remote dd if=/dev/rmt/0 ibs=1000b |tar xvf –

Where ibs is the input block size; we chose 1000b just a big number to make the read process
mach faster by reading larger blocks.

30
9 Additional information

9.1 The startup files (.cshrc et .login)


The startup files contain some commands that should be executed when you log in an
account. This allows to prepare the environment you will work in.
As the shell used is the “csh”, the files considered are the “.cshrc” and the “.login”

9.2 The environment variables


Environmental variables are used to provide information to the programs you use (exple :

Schlumberger Private
The current environment variables are displayed with the "printenv" command. Some
common ones are:
DISPLAY The graphical display to use, e.g. ainsalah:0.0
HOME Path to your home directory, e.g. /diske/student5
HOST The hostname of your system, e.g. ainsalah
PATH Paths to be searched for commands, e.g. /usr/bin:/usr/ucb:/usr/local/bin
USER Your username, e.g. student5
Many environment variables will be set automatically when you login. You can modify them
or define others with entries in your startup files or at anytime within the shell.
• To set or modify an environment variable, use this syntax:
> setenv NAME value

Where NAME is the name of the environment variable.

• You can unset an environment variable with the unsetenv command as follows:
> unsetenv NAME

• You can access to current value of the variable via the "$NAME", or "${NAME}",
notation.
Example:
> setenv PATH $PATH:/diske/student4

31
9.3 Using the manual pages of Unix (man)
The man command is used in order to give information about the way you should use a
specific command. This command is very useful in order to remind a command syntax.
Command format: man command_name
Example:
> man man

Schlumberger Private

32
Schlumberger Private
APPENDIX
Using the “vi” editor

33
Introducing vi
The visual display (vi editor) is an interactive editor that is used to create and/or modify text
files.
The vi editor uses a screen display, but you cannot use the mouse to position the cursor.
It is important that users know how to use vi editor, as it is sometimes the only editor
available (besides ed).

“vi” modes
There are three modes of operation in vi:

Schlumberger Private
• Command mode
• Entry mode
• Last-line mode

When you open a file with vi, you are in command mode. In this mode, you can enter
positioning and editing commands to perform functions. While in command mode you can do
advanced editing commands by typing a colon (:), which places you at the bottom line of the
file. This is called last-line mode. However, all commands are initiated from command mode

You must be in entry mode to enter text. To enter text you must type a vi insert command
such as i or a. This takes vi out of command mode and puts it into entry mode. In this mode,
text will not be interpreted as editing commands. When you finish entering text in your file,
press the Esc key to return to command mode.

Invoking vi
Command format:
vi [filename]
Example:
To create a new file, invoke vi with a new file name by typing:
> vi filename

34
The following table contains commands you can use to create, edit or view a file.
Command Meaning
vi filename Open or create file
vi Open new file to be named later
vi –r filename Recover crashed file
view filename Open file read-only

Input commands
Command Meaning
a Append text after cursor
A Append text at line end
i Insert text before cursor

Schlumberger Private
I Insert text at beginning of line
o Open a new line below cursor
O Open a new line above cursor

Positioning commands introduction


The following pages list the vi editor editing and positioning commands, which are used to
make changes to your file.
The vi is case sensitive, so make sure to use the specified case when using the editing and
positioning commands.
Command Meaning
h or backspace Move left one character
j Move down one line
k Move up one line
l or spacebar Move right (forward) one character
w Move forward one word (including punctuation)
W Move forward one word (past punctuation)
b Move back one word (including punctuation)
B Move back one word (past punctuation)
e Move to end of current word
Return Move down to beginning of next line
H Move to top of screen
m Move to middle of screen
L Move to bottom of screen
Control-F Page forward one screen
Control-D Scroll down one-half screen
Control-B Page back one screen
Control-U Scroll up one-half screen

35
Editing Command
Deleting text
To delete text, use the following options:
Command Meaning
x Delete character at the cursor
X Delete character to the left of the cursor
dw Delete word (or part of word to right of cursor)
3dw Delete 3 words
dd Delete the line containing the cursor
3dd Delete 3 lines
D Delete the rest of the line right of the cursor (from cursor

Schlumberger Private
position to the end of the line)
dG Delete to end of file
dlG Delete from beginning of the file to cursor
:5,10d Delete lines 5 through 10

Undoing, Repeating and changing text commands


To change text, cancel or repeat edit functions, use the following options.
The following commands (except for r) change you to insert mode until you press Esc.
Command Meaning
cw Change word (or part of word) at the cursor location to
the end of the word.
3cw Change 3 words
R Overwrite or replace characters on line
C Change from cursor to end of line
s Substitute character for string
r Replace character at cursor with one other character
i Return Break line
J Join current line and line below
xp Transpose character at cursor and character to the right
~ Change case of letter (upper or lower) at cursor
u Undo previous command
U Undo all changes to current line

36
:u Previous last line command

Copying and pasting text


Command Meaning
yy Yank a copy of line
3y Yank a copy of 3 lines
p Put yanked or deleted line below current line
P Put yanked or deleted line above current line
:1,3co5 Copy line 1 through 3 and put after line 5
:4,6m8 Move lines 4 through 6 to line8 (line6 becomes line8,
line 5 becomes line7 and line 4 becomes line 6)

Schlumberger Private
Note: Both delete and yank write to a buffer. When yanking and pasting, the paste commands
insert the text differently depending on whether you are pasting a word(s) or a line(s).

Saving and quitting files


To save and quit a file, use the following options:
Command Meaning
:w Save changes (write buffer)
:w new_file Write buffer to a new file
:wq Save changes and quit vi
ZZ Save changes and quit vi
q! Quit without saving changes

Advanced editing options


vi offers options to customize your edit session such as:
Display line numbers
Display invisible character such as tab and end of line characters.

The set commands are used from last-line to control these options
Command Meaning
:set nu Show line number
:set nonu Hide line number
:set ic Searches should ignore case
:set noic Search should be case sensitive
:set list Display invisible characters such as tab and end of line
:set nolist Turn off the display of invisible characters
:set showmode Display current mode of operation
:set noshowmode Turn off I-node display

37
To find a line, use the following options:
Command Meaning
G Go to last line of file
1G Go to first line of file
:21 Go to line 21
21G Go to line 21

To clear the screen and insert a file, use the following options:
Command Meaning

Schlumberger Private
Control-L Clear (refresh) scrambled screen
:r filename Insert (read) file at line after cursor
:34 r filename Insert file after line 34

To search and replace text, use the following option


Command Meaning
/string Search forward for string
?string Search backward for string
n Find next occurrence of string
N Find previous occurrence of string
:%s/old/new/g Search and replace globally

Creating and saving file example


The following steps describe how to create a file using the vi editor
1. Type “vi filename” to create the file
2. type “i” to insert text
3. Press Esc to go to command mode
4. Type “:wq” to write the file and exit vi
The Esc key always puts you in command mode. Use the Esc if you are not sure what mode
you are in.
If you press Esc while you are in command mode, the workstation beeps as a reminder that
you are already in command mode.

38
Schlumberger Private

39
Index
1 Logging into SunOS...............................................................................................................1
1.1 Logging in.........................................................................................................................1
1.2 How to open a terminal window.......................................................................................2
1.3 How to close a terminal window.......................................................................................2
1.4 Logging out......................................................................................................................2
2 Working with files and directories.......................................................................................2
2.1 Using File commands........................................................................................................3

Schlumberger Private
2.1.1 Before you begin........................................................................................................3
2.1.2 Creating a test file......................................................................................................3
2.1.3 Listing files (ls)..........................................................................................................3
2.1.4 Copying files (cp).......................................................................................................4
2.1.5 Moving and renaming files (mv)...............................................................................4
2.1.6 Deleting files (rm)......................................................................................................4
2.1.7 Displaying file contents (more, cat)...........................................................................5
2.1.8 Displaying file type (file)...........................................................................................5
2.1.9 Directories and hierarchy...........................................................................................5
2.1.10 Directory hierarchy..................................................................................................5
2.1.11 Print working directory............................................................................................6
2.1.12 Change working directory (cd)................................................................................6
2.1.13 Creating directory (mkdir).......................................................................................7
2.1.14 Moving and renaming directories ...........................................................................7
2.1.15 Copying directories..................................................................................................8
2.1.16 Removing directories (rmdir)...................................................................................8
2.1.17 Looking files (find)..................................................................................................8
2.1.18 File and directory security........................................................................................9
2.1.19 Displaying permission and status (ls –l)..................................................................9
2.1.20 Listing hidden files (ls –a).....................................................................................11
2.1.21 Changing permissions (chmod).............................................................................11
2.1.22 Setting absolute permissions..................................................................................13
3 Searching files.......................................................................................................................14
3.1 Searching for patterns with grep.....................................................................................14
3.1.1 Filtering using “grep”...............................................................................................15
3.1.2 “grep” with multi-word strings................................................................................15
4 Print command.....................................................................................................................16
4.1 How to submit a job (a file)............................................................................................16
4.2 How to show the status of a print job..............................................................................16
4.3 How to cancel a print job................................................................................................17
5 Passwords, processes, and disk storage..............................................................................17
5.1 Using a password............................................................................................................17
5.1.1 Changing your password..........................................................................................17

Schlumberger Private
5.2 Processes and PIDs.........................................................................................................18
5.2.1 Terminating processes using “kill”..........................................................................18
5.3 Managing disk storage....................................................................................................19
5.3.1 Displaying disk usage “df –k”.................................................................................19
5.3.2 Displaying directory usage (du)...............................................................................19
6 Handling tape devices..........................................................................................................20
6.1 The mt command............................................................................................................20
6.1.1 Rewinding a tape (using rew qualifier)....................................................................20
6.1.2 Forwarding a tape “n” files (using fsf qualifier)......................................................20
6.1.3 Checking a tape drive status (using stat qualifier)...................................................20
6.1.4 Rewinding and ejecting a tape (using rewoffl qualifier)..........................................21
6.2 Backup using “tar” command.........................................................................................21
6.3 Listing a backup file........................................................................................................21
6.4 Restore a backup file.......................................................................................................21
7 Some useful unix commands...............................................................................................22
7.1 The tcopy command........................................................................................................22
7.2 The dd command.............................................................................................................22
7.3 The wc command............................................................................................................23
7.4 The cut command............................................................................................................23
7.5 The xwd & xwud commands..........................................................................................24
8 Basic network commands....................................................................................................25
8.1 Objectives........................................................................................................................25
8.2 Client-server....................................................................................................................25
8.2.1 Distributed processing..............................................................................................25
8.2.2 Server.......................................................................................................................25
8.2.3 Client........................................................................................................................25
8.2.4 Network....................................................................................................................25
8.3 The /etc/hosts file............................................................................................................26
8.4 The rsh command............................................................................................................26
8.5 Using the ftp command...................................................................................................26
8.5.1 Copying file(s) to another machine..........................................................................26
8.5.2 Getting file(s) from another machine.......................................................................27
8.6 Log in to another machine..............................................................................................28
8.6.1 Using the rlogin command ......................................................................................28

Schlumberger Private
8.6.2 Using the telnet command........................................................................................29
8.7 Working in a remote machine.........................................................................................29
8.8 Using a remote tape drive...............................................................................................30
8.8.1 Baking up to a remote tape......................................................................................30
8.8.2 Restoring from a remote tape...................................................................................30
9 Additional information .......................................................................................................31
9.1 The startup files (.cshrc et .login)...................................................................................31
9.2 The environment variables..............................................................................................31
9.3 Using the manual pages of Unix (man)..........................................................................32
Appendix ……..………………………………………………………….…………………..33

Vous aimerez peut-être aussi