You are on page 1of 40

Agenda

 Introduction - UNIX

 General Commands

 File System Navigation

 File/Directory Manipulation

 Data Manipulation

 Networking/Communications

 Miscellaneous

 vi Editor

 sed and awk command


Introduction

Unix Evolution

1969 -- Bell Telephone Laboratories : A joint attempt by BTL, GE, and


MIT to create an OS for a large computer which can accommodate up
to a thousand simultaneous users.

 Ken Thompson and Dennis Ritchie worked on Multicast (Multiplexed


Information and Computing Service)
 BTL withdrew from the project and OS was rewritten on another
smaller machine (a DEC PDP-7 [Programmed Data Processor] with
4K memory for user programs).
 The result was a system called UNICS (UNiplexed Information and
Computing Service)
 UNICS was renamed as UNIX .
Popular versions of UNIX
SCO UNIX SCO Open Desktop and SCO Open Server from the
Santa Cruz Operation for the Intel
platform. Based on System V.
SunOS Sun’s early OS and the best-known BSD operating
system.
Solaris Sun’s SRV4 implementation, also referred to as
SunOS 5.x.
HP-UX Hewlett-Packard’s version of UNIX.HP-UX 9.x was
System V, release 3, and HP-UX 10 is based on the
System V, release 4 OS.
Digital UNIX Digital Equipment’s version of OSF/1.
IRIX The Silicon Graphics version of UNIX. Early versions
were BSD-based; version 6 is System V, release 4.
AIX IBM’s System V-based UNIX.
Linux A free UNIX operating system for the INTEL
platform.
Introduction To Unix OS

 The UNIX OS was designed :

 By programmers for programmers.


 To let a number of programmers access the computer at
the same time and share its resources.
 To control all of the commands from all of the keyboards
and all of the data being generated.
 To permit each user to believe he or she is the only
person working on the computer.

 This real-time sharing of resources make UNIX one of the


most powerful operating systems ever.
Features Of UNIX

 Multitasking capability
 Multi-user capability
 Portability
 UNIX tools :
 Integral
 Non -Integral
 UNIX Communications
 Applications libraries
UNIX Organization

Kernel : schedules tasks and manages storage;


Shell : connects and interprets users' commands, calls programs from
memory, and executes them .
Tools and applications : offer additional functionality to OS.
General

 exit : Terminate your current session, or shell.

 man command : Display the Unix manual page


describing a given Unix command.

 login : Type the userid,


press ENTER and supply the password

 To logout : exit

To change the password :

$passwd [ENTER]
General

 pwd : writes an absolute path name of the


current working directory to standard output.

 cd, chdir :  change working directory


The who Utility

The who utility can list :

 the user's name


 terminal line
 login time
 elapsed time since activity occurred on the line
 the process-ID of the command interpreter (shell).

 File /var/adm/wtmp, contains a history of all the logins


The general format for output is:
name [state] line time [idle] [pid] [comment] [exit]
File System Navigation

 cd : Return to your home directory.


 cd directory : Change directory to make directory your current
directory.
 file files : Determine file type.
 ls : List the contents of the current directory.
 ls names : List the contents of the directories; names can name
files and/or directories:
 ls -l : . . . in a long format, showing permissions, owner, size,
and other file info.
 ls -a : . . . all files, including "hidden" files (file names that begin
with a dot ".").
 ls –R : . . . Recursively, for all subdirectories.
 ls -t : . . . in time order (when modified, newest to oldest) rather
than in name order.
 pwd : Display the name of the current directory, or "print
working directory."
File/Directory Manipulation

 compress files : Reduces the size of a file.


 uncompress files : Restores compressed files to their original form.
 cp file1 file2 : Copy file(s).
 cp files directory : Copy file(s) into a directory.
 cp -r dir1 dir2 : Copy a directory and, recursively, its subdirectories.
 mkdir directory : Create, or "make" a directory.
 mv file1 file2 : Move a file or, if file1 and file2 are in the same
directory, rename a file.
 mv files directory : Move files into a directory.
 mv dir1 dir2 : If directory dir2 exists, move dir1 into dir2; otherwise,
rename dir1 as dir2.
 rm files : Remove (erase) file(s).
 rm -r names : Remove files, directories, and recursively, any
subdirectories.
 rmdir directory : Remove directory (directory must be empty).
Data Manipulation

 cat files : Concatenate file(s); you can use cat to display the
contents of a file (this is not advisable if the file is a binary file).

 grep "pattern" files : Display all lines in the files that match a pattern.

 more files : Display contents of files one screen at a time.

 sort files : Order the lines in a file or files alphabetically (this


command does not alter the file or files -- it merely displays the
sorted output to the screen):

 sort -r files : . . . in reverse order.


Networking/Communications

 ssh hostname : Connect to a remote host using Secure Shell.


 telnet hostname : Connect to a remote host using the telnet
protocol.
 talk user : Initiate a conversation with another user (end
conversation with Control-C); talk works only between machines of
the same architecture
 ftp : The command file transfer protocol attaches you to another IP
device
e.g.
ftp 141.205.15.154 ( Attaches you to the device with
address 141.205.15.154. You are normally presented with a login
and password screen )
Networking/Communications

 Commands that are used in FTP are:

 dir - directory listing.


 quit - quit from ftp.
 cd - change directory.
 get or mget - get a file (or multiple files).
 put or mput - put a file (or multiple files).
 bin - sets up your system to receive binary files.
 hash - displays hashes whilst files are being transferred.
 lcd - local change directory changes the directory on your local
machine to which you are sending and receiving files. This is useful
as it saves you having to quit ftp to carry out the directory change.

The Hosts file can be found in the directory '/etc'.


Networking/Communications
 netstat : This stands for network statistics,
e.g.
netstat -r displays the routing table of the Unix box.
netstat -a displays all network information.

 ping : Ping an IP device


e.g.
ping 141.205.51.26

 rlogin : This works like telnet,


e.g.
rlogin 141.205.52.16 takes you to another Unix machine
only. To quit you press 'return', '~', .' and 'return' again.

 Ifconfig : This displays the IP configuration of the box, e.g.


e.g.
ifconfig -a displays all IP configuration.
Networking/Communications

 snoop : This command captures the network packets in


a readable format
e.g.
snoop -p 23 ( Captures all IP traffic using port 23
(Telnet). use Ctrl-C to stop the snoop.)

 vstat : This displays CPU utilization and gives a list of


processes and their share of CPU utilization,
e.g.
vstat 10 ( displays the CPU utilization every 10
seconds.)
Miscellaneous

 !! : Repeat last shell command.


 !string : Repeat last shell command that began with string (for example, type
"!m" to repeat the last command that began with "m").
 cal : Display a calendar of the current month.
 cal month year : Display a calendar of the given month and year. Note that
the year must be fully qualified, for example, "2003" and not "03."
 clear : Clears terminal screen.
 date : Display the current local date and time.

Difference between who am i, whoami:

who am i : tells me who I am. prompt who am i

On the other hand,

whoami : displays the effective current username.


df

Displays number of free disk blocks and files .

 -a Report on all file systems


 -b Print the total number of kilobytes free.
 -e Print only the number of files free.
 -F FSType Specify the FSType on which to operate.
The -F option is intended for use with unmounted file
systems.
 -l Report on local file systems only.
 -n Print only the FSType name.
 -o FSType-specific_options
 -t Print full listings with totals.
-V Echo the complete set of file system specific command
lines
du

 Reports on number of 512 bytes blocks of


every directory in the system.
The Find Utility
recursively descends the directory hierarchy for each
path seeking files that match a Boolean expression
written in the primaries given below.
SYNOPSIS
find path... Expression
Example :
$find / -name passwd –print
$find –user singh –print
$find –name <file_name> -print
cat

The cat utility reads each


file in sequence and
writes it on the
standard output cat [-nbsuvet] [file]...
SYNOPSIS
-n Precede each line output
example with its line number.
cat file -b as -n, but omit the line
cat file1 file2 >file3 numbers from blank lines.
-u The output is not buffered.
-s silent about non-existent
files.
-v Non-printing characters are
printed visibly
File access

$ cat > homefiles


echo "files in the home directory \n”
cd;pwd
ls -l |more

$ chmod +x homefiles
chmod

 chmod changes or assigns the mode of a file. The


mode of a file specifies its permissions and other
attributes.
 The mode may be absolute or symbolic.

u user + add permission r=4 read permission


g group - remove permission w=2 write permission
o other = Enable setting x=1 execute permission
Examples : chmod

Deny execute permission to everyone: chmod a-x file


Allow only read permission to everyone: chmod 444
file
Make a file readable and writable by the group and
others:
chmod go+rw file
chmod 066 file
Allow everyone to read, write, and execute the file and
turn on the set group-ID.
chmod a=rwx,g+s file
chmod 2777 file
grep utility

 The grep utility searches text files for a pattern and prints
all lines that contain that -pattern
grep [-bchilnsvw] limited-regular-expression [filename]
wc utility
 The wc utility reads one or more input files and, by default,
writes the number of newline characters, words and bytes
contained in each input file to the standard output.
wc [ -c| -m| -C] [-lw] [file]
-c Count bytes.
-m and -C Count characters.
-l Count lines.
-w Count words delimited by white space
characters or new line characters.
Example :
#wc -clw xxx.txt
More, Page

 More : Browse or page through a text file .


 page : page through a text file .

 Examples :
more /etc/passwd
more /etc/inittab
head & tail

The head / tail utility copies the first/last number of lines


of each filename to the standard output.
The default value of number is 10 lines.

Example :
$Head -10 phone.txt
$tail +5 phone.txt
cmp ,diff ,EOF, BOF

cmp utility compares two files and reports the first


difference that id fineds.

diff utility echoes the different lines.

Examples :
diff phone.txt phone.old
diff phone.txt phone.old
Printing files

1. Using cat & cp commands (if printer is connected to


terminal port 8):
cat phone.txt > /dev/tty8
cp /etc/inittab /dev/tty8

2. If printer is directly connected to the serial printer port on


the CPU
cat phone.txt >/dev/ptrs

3. To know the status of the printer : lpstat –t

4. Adding files to print-job queue :


lp chap1 chap2 chap3
ps utility

ps (process status) : for viewing the status of all


the unfinished jobs that have been submitted to
the kernel.
Example:
ps -ef
ps -ef | grep yourusername

-e option : include all processes (including others)


-f option : give a long listing.
Killing processes

Use kill utility to terminate processes.


Some processes refuse to die easily, use the "-9"
option to force termination of the job.

EXAMPLE: force termination of a job whose process ID


is 111

kill -9 111
tar

 The "tar" command stands for tape archive.

 This command is used to create new archives, list


files in existing archives, and extract files from
archives.
Vi Editor

The VI editor is a screen-based editor used by many Unix users. The VI editor
uses the full screen, so it needs to know what kind of terminal you have. When
you log in, wiliki should ask you what terminal you have. The prompt looks like
this: TERM = (vt100)

 For C shell (/bin/csh), the command is this:


set term=vt100
For Bourne Shell (/bin/sh) or Korn Shell (/bin/ksh), the commands are the
following:
export TERM
TERM=vt100

Next, reset your terminal with this command:


tset

 Starting the vi Editor

The vi editor lets a user create new files or edit existing files. The command to
start the vi editor is vi, followed by the filename.
Vi Editor
 vi <filename> or < no filename >( it will ask filename
while saving the file.)

 Useful vi commands

 i : insert mode.
 <esc> : leave insert mode and go into command
mode.
 a : append characters to the end of the line.
 o : open a line below your cursor.
 O : open a line above.
 <shift>g : go to the bottom of the file.
 r : replace the letter that you are on with the one you
 type next.
Vi Editor

 x erase the character that you are on.


 dd delete the line that you are on. A number before dd deletes that
number of lines.
 yy copy the line you are on. A number before yy copies that number of
lines.
 p paste the line you are on below you.
 P paste the line you are on above you.
 :wq write and quit the file that you are editing.
 :wq! write and quit the file that you are editing, even if it is designated as
read only!
 :w! write to a read only file.
 :q quit.
 :q! discard any editing and quit.
 / this takes you to the bottom of the window where you can type a string
and return to perform a search in the file.

 Note : (The character ! is often referred to as pling )


sed Command

A stream editor.

 Syntax

sed [  -n ] Script [ File ... ]
sed [  -n ] [  -e Script ] ... [  -f ScriptFile ] ... [ File ... ]

 Description

 The sed command modifies lines from the specified File parameter according
to an edit script and writes them to standard output. The sed command
includes many features for selecting lines to be modified and making
changes only to the selected lines.
 The sed command uses two work spaces for holding the line being modified:
the pattern space, where the selected line is held; and the hold space, where
a line can be stored temporarily.
awk Command

Finds lines in files that match patterns and then performs specified actions on them.

 Syntax

awk [ -F Ere ] [ -v Assignment ] ... { -f ProgramFile | 'Program' } [ [ File ... | Assignment ... ] ] ...

Description

 The awk command utilizes a set of user-supplied instructions to compare a set of files, one line
at a time, to extended regular expressions supplied by the user. Then actions are performed
upon any line that matches the extended regular expressions. The maximum record size that
awk processes is 10KB.

 The pattern searching of the awk command is more general than that of the grep command,
and it allows the user to perform multiple actions on input text lines. The awk command
programming language requires no compiling, and allows the user to use variables, numeric
functions, string functions, and logical operators.

 The awk command is affected by the LANG, LC_ALL, LC_COLLATE, LC_CTYPE,


LC_MESSAGES, LC_NUMERIC, NLSPATH, and PATH environment variables.
Thank
You

You might also like