You are on page 1of 54

"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Section 3

About UNIX

3-1
Objectives

This section introduces UNIX to those who are new to UNIX, and helps the
other students to recall the basic functions and commands of UNIX.
"Confidential information -- may not be copied or disclosed without permission".

It offers an Unix approach based on 4 levels:


Unix overview defining UNIX user, user groups, UNIX accounts,
access rights.
Some basic UNIX commands describing some of the most basic and
widely used commands.
Some advanced commands describing a few useful advanced
commands.
Devices Management defining the devices system in Solaris 2.5.1
and describing its management.
At the end of this section you can find a description of the VI text editor
functions, which can be useful at the four levels.

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-2


Contents

UNIX Overview
"Confidential information -- may not be copied or disclosed without permission".

Some Basic UNIX Commands

Some Advanced UNIX Commands

Devices Management

Text Editor

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-3


"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Student Notes

3-4
"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
UNIX Overview

3-5
UNIX Overview

The UNIX user:


"Confidential information -- may not be copied or disclosed without permission".

is defined by: a user name

a password

an environment

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-6


UNIX Overview

The UNIX super-user:


"Confidential information -- may not be copied or disclosed without permission".

name: root

special feature: privileged user


with the full set of access rights

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-7


UNIX Overview

Defining user groups: file /etc/group

Definition line (for example):


"Confidential information -- may not be copied or disclosed without permission".

omc::100:omc,rot

Format:

omc : group name

<empty> : group password

100 : group identity number (one-of-a-kind)

omc, rot : list of users

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-8


UNIX Overview

Defining UNIX accounts: file /etc/passwd


Definition line (for example):

omc:X:102:100:omc account: /home/omc:/bin/csh


"Confidential information -- may not be copied or disclosed without permission".

Format:
omc : user name
X : see /etc/shadow
102 : user identity number (one-of-a-kind)
100 : number of users group
omc account : comments
/home/omc : home directory
/bin/csh : command executed at log in time

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-9


UNIX Overview
OMC Application Accounts
"Confidential information -- may not be copied or disclosed without permission".

home
Account Password uid gid process
directory

omc X 100 100 /home/omc /bin/csh

rot X 101 100 /OMC/diagnostic /OMC/exe/MmiLineInput.x

sybase X 11 11 /opt/sybase /bin/csh

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-10


UNIX Overview

Access rights

--- --- ---


"Confidential information -- may not be copied or disclosed without permission".

u g o
u = user g = group o = other
each - stands for the users rights in:
r = read mode
w = write mode
x = run mode

Example: rwx-w---x (721 in octal notation)

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-11


UNIX Overview
Main Default Directories
"Confidential information -- may not be copied or disclosed without permission".

/etc /proc /home /usr /var /kernel /opt /tmp

/home/usera /home/userb /home/omc

.cshrc .login .mwmrc

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-12


UNIX Overview

The home directory in the user accounts contains the files defining the
environment
"Confidential information -- may not be copied or disclosed without permission".

Example: omc account


.cshrc
.login
.openwin_init
.mwmrc
.Xinitrc

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-13


"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Student Notes

3-14
"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Some Basic UNIX Commands

3-15
Some Basic UNIX Commands

The man command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : to obtain the UNIX document set and on-line help

Structure : man <command name>

Response : extract of the UNIX user guide

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-16


Some Basic UNIX Commands

The ls command
Purpose : lists a directorys contents
"Confidential information -- may not be copied or disclosed without permission".

Options :

-l : lists directory contents with the following information:


- mode (d=directory, l=file)
- number of links
- owner, size
- date of last access

-al : lists directory contents with access rights

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-17


Some Basic UNIX Commands

Introduction
The pwd command shows in what directory you currently reside.

Description
The command pwd stands for print working directory. It prints the path name
"Confidential information -- may not be copied or disclosed without permission".

of the current directory on its standard output.


You can move down or up along a directory tree using this command and the
Command cd. As an example, you can move down as follows:

pwd
/home/omc
cd..
pwd
/home
cd..
pwd
/

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-18


Some Basic UNIX Commands

The ps command
Purpose : obtains the list and states of processes
"Confidential information -- may not be copied or disclosed without permission".

Structure : ps [options]
Main options:
e: informs the user each time a process is executed
d: informs the user each time a process is executed, except
when process group parents are executed
a: informs the user each time the mostused processes are
executed
f : gives full information about the processes displayed by
the above options

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-19


Some Basic UNIX Commands

The lp command
"Confidential information -- may not be copied or disclosed without permission".

Purpose : to output a file to printer

Structure : lp -[options] [file]

Main options:
-m : prints the file then mails the job report

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-20


Some Basic UNIX Commands

The cat, more commands


"Confidential information -- may not be copied or disclosed without permission".

Purpose : to display a file on the screen

Structure : cat <file name>

Variant : cat file1 > file2 copies file1 to file2

Filter : the more filter


cat file | more to step through screen displays
(equivalent to: more file)

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-21


Some Basic UNIX Commands

The cp command

Purpose : copies a file


"Confidential information -- may not be copied or disclosed without permission".

Structure : cp file1 file2

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-22


Some Basic UNIX Commands

The rm command
"Confidential information -- may not be copied or disclosed without permission".

Purpose : to delete files or links

Main options:

-f : silently

-r : recursively

-i : interactively

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-23


Some Basic UNIX Commands

The cmp command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : to compare two files

Main options:

-l : shows the character differences in the two files

-s : shows nothing, only generates a return code

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-24


Some Basic UNIX Commands

The mkdir command

Purpose : creates a directory


"Confidential information -- may not be copied or disclosed without permission".

The rmdir command

Purpose : removes a directory

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-25


Some Basic UNIX Commands

The find command

Main options:
"Confidential information -- may not be copied or disclosed without permission".

path_name_list : Where the research has to be done


-name file : TRUE if file is the current file name
-links n : TRUE if the file has n links
-user uname : TRUE if the file belongs to uname
-atime n : TRUE if the file has been accessed some time
within n days
-print : Always TRUE; causes the current path name to
be printed

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-26


Some Basic UNIX Commands

The grep command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : to locate an expression in a file

Structure : grep [options] /expression/ [file name]

Main options :

-v : displays the lines not containing the expression

-c : counts the lines containing the expression

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-27


Some Basic UNIX Commands

The cd command
"Confidential information -- may not be copied or disclosed without permission".

Purpose : to move through the tree

Structure : cd path_of_file_to_reach

absolute path : starting from the root


eg: /rep1/rep2/rep_current
relative path : starting from where you are now
current directory: .
parent of current directory: ..

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-28


Some Basic UNIX Commands

The pipe command


"Confidential information -- may not be copied or disclosed without permission".

Structure : command1 | Command2

Purpose : appends standard output from command1 to the


standard input of command2

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-29


Some Basic UNIX Commands

Special characters:
. : any character
"Confidential information -- may not be copied or disclosed without permission".

\ : do not value the next character


* : 0 or n occurrences of the character before the *
[abc] : a or b or c
/^.../ : that begins with ...
/$.../ : that ends with ...

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-30


"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Some Advanced UNIX Commands

3-31
Some Advanced UNIX Commands

The passwd command


changes a users password
"Confidential information -- may not be copied or disclosed without permission".

Purpose :

Structure : passwd <user name>


Enter the new password.
Re-enter the new password.

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-32


Some Advanced UNIX Commands

The tar command


Purpose : archives some directory trees on a storage unit
"Confidential information -- may not be copied or disclosed without permission".

Structure : tar [keys] [sub-tree name] [device name]

Options:
c back up to a blank tape
r back up at the end of a tape containing tar command results
x restore from a tape or extract from another machine
t list tape contents
v verbose
p keep same rights

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-33


Some Advanced UNIX Commands

The crontab command (1/2)


"Confidential information -- may not be copied or disclosed without permission".

Purpose : to manage the command files belonging to a user

Main options :

-e : edits the command file


-l : lists command files
-r : removes command files

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-34


Some Advanced UNIX Commands

The crontab command (2/2)


"Confidential information -- may not be copied or disclosed without permission".

Purpose : to manage the command files belonging to a user

Main options :

-e : edits the command file


-l : lists command files
-r : removes command files

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-35


Some Advanced UNIX Commands

The df-k command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : to display the number of free blocks in a disk volume

-k option : to display the volumes size in kbytes

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-36


Some Advanced UNIX Commands

The chmod command (1/2)


"Confidential information -- may not be copied or disclosed without permission".

Purpose : changes a file or directorys access mode

Structure : chmod for_who operation permission resource


for_who : u (user) or g (group) or b (others)
operation : + (add a right), (remove a right)
permission : r: read mode, w: write mode, x: run mode

Example : chmod g+w read.c


chmod 644 read.c (octal notation)

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-37


Some Advanced UNIX Commands

The chmod command (1/2)


"Confidential information -- may not be copied or disclosed without permission".

Purpose : changes a file or directorys access mode

Structure : chmod for_who operation permission resource


for_who : u (user) or g (group) or b (others)
operation : + (add a right), (remove a right)
permission : r: read mode, w: write mode, x: run mode

Example : chmod g+w read.c


chmod 644 read.c (octal notation)

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-38


Some Advanced UNIX Commands

The kill command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : kills a process

Structure : kill [process id number]

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-39


Some Advanced UNIX Commands

The rlogin command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : logs into a station from a remote station

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-40


Some Advanced UNIX Commands

The rsh command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : runs a shell on a remote machine

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-41


Some Advanced UNIX Commands

The rcp command


"Confidential information -- may not be copied or disclosed without permission".

Purpose : copies onto or from a remote station


- p: preserves the modification time and modes
-r: when file1 is a directory

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-42


"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Devices Management

3-43
Devices Management

Access to hard disks


"Confidential information -- may not be copied or disclosed without permission".

Numbering:

/dev/dsk/ c0 t3 d0 s0

Number of partition
SCSI logical unit number
SCSI target
SCSI controller number

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-44


Devices Management

Access to tape drive


/dev/rmt/0
"Confidential information -- may not be copied or disclosed without permission".

Access to floppy drive (workstation only)


use mount a floppy disk from background menu
use the df -k command to know the mount_point
(/dev/df or /floppy/floppy_name)

Access to CD-ROM
automatic with File Manager

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-45


"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Student Notes

3-46
"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Text Editor

3-47
Text Editor

Text editor: VI
Features:
"Confidential information -- may not be copied or disclosed without permission".

standard
full screen display
2 modes: line mode and command mode
~ indicate additional lines

Command mode:
[ESC] for enter
1, 2, or 3 character requests

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-48


Text Editor

The save and quit commands


"Confidential information -- may not be copied or disclosed without permission".

purpose : to display the number of free blocks in a disk volume

:q : to quit

:q! : to quit without saving

:w : to save

:wq : to quit and save

:x : to quit and save (for system files and root user only)

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-49


Text Editor

Cut / copy / paste

Cut
x : a character
"Confidential information -- may not be copied or disclosed without permission".

dw : a word
dd : a line
D : end of line

Copy
Y : a line

Paste
p : after below
P : in front of above

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-50


Text Editor

Moving around
Character / word
"Confidential information -- may not be copied or disclosed without permission".

h, j, k, l : left, down, up, right


w (or W) and b (or B) : in front of and after word

Line
H, L : first line, last line
0, $ : start, end of line
nG : go to line n

Screen
^F and ^B : next page and previous page
^L : refresh screen

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-51


Text Editor

Inserting text
"Confidential information -- may not be copied or disclosed without permission".

a : add the text after the cursor


A : add the text to the end of the line
i : add the text in front of the cursor
I : add the text at the beginning of the line
o : insert one line below
O : insert on line above
R : overwrite the existing text

PE/TRD/CN/0303 12.02/EN March, 2000 About Unix 3-52


"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Student Notes

3-53
"Confidential information -- may not be copied or disclosed without permission".

PE/TRD/CN/0303 12.02/EN
March, 2000
About Unix
Student Notes

3-54

You might also like