SlideShare a Scribd company logo
1 of 59
UNIX OS
&
BASIC
UNIX COMMANDS
--Mohit

chandra belwal
Operating Systems
An Operating System controls (manages)
hardware and software.
provides support for peripherals such as
keyboard, mouse, screen, disk drives, …
software applications use the OS to
communicate with peripherals.
The OS typically manages (starts, stops,
pauses, etc) applications.
Understanding Operating
Systems

3
• What Is UNIX?
UNIX is a computer operating system, a
control program that works with users to
run programs,
manage resources, and
communicate with other computer systems.

Several people can use a UNIX computer at
the same time; hence UNIX is called a
multiuser system. Any of these users can also
run multiple programs at the same time;
hence UNIX is called multitasking.
4
Introduction to Unix
 Unix was born in 1969 at Bell Laboratories, a research
subdivision of American Telephone and Telegraph Company.
 Some of the functions of the Unix operating system are:
it provides a filing system (write, copy, rename, move
files)
it provides for the loading and executing of the user
programs
it provides a communication link between the computer
and its accessories (input-output devices as terminals,
printers, disks, etc).
UNIX
 Hardware is surrounded by the operating system
software
 Operating system is called the system kernel

The kernel is the core of an operating system and
manages the machine’s hardware resources (including
the processor and the memory), and provides and
controls the way any other software component can
access these resources.
The kernel runs with a higher privilege than other
programs.

 Comes with a number of user services and interfaces
Shell
Components of the C compiler
GUI or Command Line Interface
Layers of a UNIX System

Hardware

Kernel
System Calls

Shells, ls, cp, etc.
Netscape, vi, pine, etc.
8
Simple Unix
Directory Structure
/
usr

etc

local bin ... class
u1

home

bin

home ugrad ...
u2

...

var ...
Unix File System
Top most
directory in Unix

root

usr

var

etc

rdefe

Home
Directory

home

jsmith

djones

data

mbox, letter,
prog1, prog2

jan

feb

file1, file2,
file3, file4

save

lib

mbox, jandat
info

Directory
containing all
home
directories

x1, x2, x3, x4

file1, file2,
file3, file4

10
Unix File System
Home Directory
Personal Directory to store files
Usually the Directory Name = login ID
Current Directory after successful login
root

usr

home

etc

rdefe

Home directories for:
rdefe, jsmith and
djones

var

jsmith

djones

data

mbox, letter,
prog1, prog2

jan

feb

file1, file2,
file3, file4

save

lib

mbox, jandat
info

x1, x2, x3, x4

file1, file2,
file3, file4

11
Introducing UNIX Shells
A shell is a
UNIX program
that interprets
the commands
you enter from
the keyboard

12
Choosing Your Shell
Shells interpret commands and act as firstclass programming languages
A default shell is associated with your account
when created – Bash is the default shell in
Linux
A short list of some UNIX shells:
Bourne
Cshell
Korn
Bash
13
Logging in to UNIX
Log in by entering username and password
when UNIX system booted or connected to
Enter at prompt (command-line mode) or
into login box (GUI mode)
You’re at the Shell prompt -- Now
commands can be issued at the command
prompt

14
Entering Commands
To interact with UNIX, a command is
entered at the command prompt
UNIX is case-sensitive and most commands
are typed in lower case
Two categories of commands
User-level: perform tasks
System administration: system management

15
Unix Commands
 passwd : Change your password.
This will let you enter a new password. Use a password
that is not a real word or name and has numbers or
punctuation in it.
Usage: #passwd
 who



By typing “who” you will get a list with all the people
logged in at that moment. The leftmost column shows the
terminal at which the person is working, the next column
shows the date and the rightmost column shows the
computer number (IP number).
who am i
This Check the current being user.It returns username that
you are using.

16
Unix commands
Passwd command usage:
sariyer:~> passwd
Changing password for dag.
Old password:
New passwd:
Retype new passwd:
sariyer:~>

17
Unix Commands
 man
Show any UNIX command usages.
“man command” shows purpose of command, its format,
how to specify options and usage examples. We should use
“man” to learn more about Unix commands given in this
documents.
Usage: #man who

 cal
Shows calendar of the current month.
Usage: #cal
18
Unix Commands
The man program
displays the UNIX
online reference
manual, called the
man pages, for
help purposes
To exit
Press “q”
19
Unix Commands

20
Unix Commands
 ps
Show process status.
“ps” show processes own by your user. “ps –ax”
shows all processes currently running on your
server. The output is formatted in columns. First
column is process ID, second column is process
status and last column is command name.

21
Unix Commands
 mkdir
Create a new directory.
“mkdir dirname” will create a new subdirectory called
“dirname”.
Usage: #mkdir test

 rmdir
Create a new directory.
“rmdir dirname” will remove a subdirectory “dirname”.
The directory must be completely empty of files.
Usage: #rmdir test
22
Unix Commands
 cp
Copy a file.
“cp src dest” will make an exact copy of file “src” , with the name
“dest”. If “dest” is a subdirectory name, the command will instead
copy file “src” into the subdirectory “dest” and use its original file
name.

 mv

Move (rename) a file.
“mv src dest” will move file “src” to file “dest”. If “dest” is a
subdirectory name, the command will instead move file into the
subdirectory “dest” and use its original file name.

 rm

Remove (delete) a file..
“rm filename” will delete “filename”. Once it is removed, there is no
way to get it back!

23
Unix Commands
ls
List Files & Directories
$ ls
198
A
aa.bb.cc.dd
bin
datefile
etc
mail
mbox
mbox.old
unix
$
24
Unix Commands
ls -p
-p Show Directories
$ ls -p
198
A
aa.bb.cc.dd
bin/
datefile
etc/
mail/
mbox
mbox.old
unix/
$
25
Unix Commands
ls [directory1] [directory2] ...
List the contents of a directory
$ ls -p
198
A
aa.bb.cc.dd
bin/
datefile
etc/
mail/
mbox
mbox.old
unix/
$

$ ls unix
awk.data
awk.prg
bgraph
cpy
homework2
homework3
unix2test
$
26
Unix Commands
ls -s
-s Show File Size in Blocks
Block Sizes
$ ls -s
512 bytes
1024 bytes
2048 bytes

total 19
1 198
1A
1 aa.bb.cc.dd
1 bin
1 datefile
1 etc
1 mail
2 mbox
1 unix

27
Unix Commands
ls -l
-l Long Listing
$ ls -l
total 19
-rw-r--r--rw-r--r-drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
-rw------drwxr-xr-x
$

1
1
2
3
2
2
1
2

rdefe
rdefe
rdefe
rdefe
rdefe
rdefe
rdefe
rdefe

unix
unix
unix
unix
unix
unix
unix
unix

53
62
96
80
64
32
984
144

Sep
Sep
Sep
Aug
Aug
Sep
Sep
Aug

12
12
4
29
29
2
12
29

21:46
21:47
20:58
20:54
20:54
1992
21:44
20:54

198
A
bin
db
etc
mail
mbox
unix

28
Unix Commands
ls -a
-a List All Files

Include Files That
Begin with a ‘.’
Files that begin with a ‘.’ are usually
configuration files

$ ls -a

.
..
.profile
.sh_history
198
A
bin
datefile
db
etc
mbox
unix
$
29
Unix Commands
ls -r
-r Reverse Sort

ls -R
-R List Contents of

Subdirectories

• List files in each subdirectory.
• Subdirectories with Subdirectories
will also be listed…and so on...

$ ls -r
unix
mbox
mail
etc
db
datefile
bin
A
198
$
30
Unix Commands
ls -l -t

or

ls -lt

-t Sort On Modification Time
$ ls -lt
total 19
-rw-r--r--rw-r--r--rw------drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
$

1
1
1
2
2
2
3
2

rdefe
rdefe
rdefe
rdefe
rdefe
rdefe
rdefe
rdefe

unix
unix
unix
unix
unix
unix
unix
unix

62
53
984
96
64
144
80
32

Sep
Sep
Sep
Sep
Aug
Aug
Aug
Sep

12
12
12
4
29
29
29
2

21:47
21:46
21:44
20:58
20:54
20:54
20:54
1992

A
198
mbox
bin
etc
unix
db
mail

31
Unix Commands
or

ls -l -t -r

ls -ltr

-tr Reverse Sort On Modification Time
$ ls -ltr
total 19
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
-rw-------rw-r--r--rw-r--r-$

2
3
2
2
2
1
1
1

rdefe
rdefe
rdefe
rdefe
rdefe
rdefe
rdefe
rdefe

unix
unix
unix
unix
unix
unix
unix
unix

32
80
144
64
96
984
53
62

Sep
Aug
Aug
Aug
Sep
Sep
Sep
Sep

2
29
29
29
4
12
12
12

1992
20:54
20:54
20:54
20:58
21:44
21:46
21:47

mail
db
unix
etc
bin
mbox
198
A

32
Unix Commands
cat [Filename1] [Filename2] …
Concatenate Files
Display Files to the Screen
Ctrl-s Pause Screen
Ctrl-q Unpause Screen
$ cat sample.file
This is a sample file that i'll use to demo how
the pr command is used.
The pr command is useful in formatting
various types of text files.
$
33
Unix commands
cat command usage:

Prompt

Command
İf you type this row
and then press
enter

The text indicates what we
typed to cat

34
Unix Commands
more [Filename1] [Filename2] …
Display Files to the screen one page at a
time
$ more largefile
This is a sample file that i'll use to demo how
the pr command is used.
The pr command is useful in formatting
various types of text files.
--More--(16%)

 Spacebar (next page)
 b (previous page)
 Enter Key (next line)






q (Quit & return to unix)
/string (search for string)
:n (next file)
:p (previous file)

35
Unix Commands
pr [Filename1] [Filename2] …
Format & Display Files to the Screen
$ pr sample.file
98-05-22 23:07

sample.file

Page 1

This is a sample file that i'll use to demo how
the pr command is used.
The pr command is useful in formatting
various types of text files.
$
36
Unix Commands
pr -[dn] [Filename1] [Filename2] …
-d Double Space Output
-n Number Lines

$ pr -d sample.file
98-05-22 23:07

sample.file

Page 1

$ pr -n sample.file
This is a sample file that i'll use to demo how
98-05-22 23:07
the pr command is used.

sample.file

Page 1

1
This is a sample file that i'll use to demo how the
The pr command is useful in formatting
2
pr command is used.
3
The pr command is useful in formatting
various types of text files.
4
various types of text files.
$
$
37
Unix Commands
 grep
Search file and print lines that match pattern.
“grep pattern filename” will print out each line
in file “filename” that contains “pattern”. It is
case-sensitive search.

38
Unix Commands
lpr [Filename1] [Filename2] …

Send Files to a Unix Printer
No Formatting (page numbers, etc.)

$ lpr prog1 mbox
$
$ pr sample.file

Ideal solution would
be to combine the
lpr & pr to achieve
formatted printed
output

98-05-22 23:07 sample.file Page 1
This is a sample file that i'll use
to demo how the pr command is used.

...
39
Unix Redirection
Output Normally Displayed to the Screen
is Redirected and Becomes the Input to
Another Command

$ pr prog1 | lpr
$

40
Unix Redirection
The Output of One Command can be used
as the Input to Another
$ pr prog1 | lpr
$
Command that
generates screen
output

Command | Command
Command that
requires input
41
Unix Redirection

Command | Command | Command ...
$ ls | pr | lpr
$
Directory Listing Formatted
Using pr, Printed on Paper

42
Unix Redirection
Output Normally Displayed to the Screen
Can Be Redirected to a File

$ pr prog1 > prog1.pr
$
Note: Nothing is displayed to
the screen

The file prog1.pr contains
the output of the pr command
43
Unix Redirection
Redirecting Output
The Output of Command can be saved to a
File
$ pr prog1 > prog1.pr
$

Command that
generates screen
output

Command > File
File used to capture
(save) screen output
Caution: Output File will
be erased if it already
exists.
44
Redirection Examples
1

$ pr data > data.pr
$ lpr data.pr

2

$ cal 3 1993 > year

Using arguments with redirection

3

$ ls -l data > stuff

Using arguments & options with
redirection

Is the same as

$ pr data | lpr

45
Redirection Examples
4

$ pr data > lpr

5

$ cat text let > mesg

6

$ pr f1 f2 > f1
1
2

Create the file f1
Erases f1 if it already
exists

pr f1 and f2, redirect to f1
46
Unix Commands
 head
“head” will display the first ten lines in the listed
files.
head [- lines] [file1 file2 ... fileN]
Any numeric option will be taken as the number
of lines to print, so head -15 frog will print the
first fifteen lines of the file frog.

47
Unix Commands
 tail
Like head, tail display the last ten lines in the
listed files.
tail [- lines] [file1 file2 ... fileN]
Any numeric option will be taken as the number
of lines to print, so tail -15 frog will print the last
fifteen lines of the file frog.

48
Unix Commands
 wc
wc (word count) simply counts the number of
words, lines, and characters in the file(s).
wc [-clw] [file1 file2 ... fileN]
The three parameters, clw, stand for
character, line, and word respectively, and tell wc
which of the three to count.

49
Unix Commands
 cmp
cmp compares two files.
cmp is very simple, and merely tells you where
the two files first differ.
cmp file1 [ file2]

50
Unix Commands
vi [Filename]
Full Screen, Visual Editor
Changes Displayed As They Are Made
Edits A Copy of the File
Changes Must Be Saved
$ vi mesg

51
Unix Commands
Vi Modes
Command Mode
Start in command mode
Every Key Performs an Editing Command

Insert Mode
Perform Text Entry/Input
Insert Mode Command

Command Mode

Insert Mode

ESC Key
52
Sample vi Edit Session
$ vi mesg







Welcome to UNIX

Wnewtextelcome to UNIX
This is an example of
a text file in vi
This is an example of
~
a text file in vi
~
~
~
~
:wq
$

Start in Command Mode
Press a key for Append After Cursor Command
Enter text (Input Mode)
Press ESC key (Command Mode)
Press :wq followed by Enter key to Save & Exit

53
Cursor Positioning
Moving the Cursor in Command Mode
k
Key

h

l

j

w
b
Cntrl-d
Cntrl-u
Enter
G
5G

Command
Forward One Word
Backward One Word
Scroll Down
Scroll Up
Down One Line
Go To Last Line
Go To Line 5
54
Text Input Mode
vi Text Input Mode Commands
Wnewtextelcome to UNIX

a Append After Cursor

Welcome to UNIXnewtext
This is an example of
A Append at End of Line
a text file in vi
newtextWelcome
~ This is an example ofto UNIX
i Insert Before Cursor
~ a text file in vi
is an example of
~ ThisnewtextWelcome to UNIX
I Insert at Beginning of
~ a text file in vi
Line
~ This is an example of
newtext
~ a text file in vi
O Open New Line Above Cursor
Welcome to UNIX
~
o Open New Line Below Cursor
~ This is an example of
R Replace Text (typeover)
a text file in vi
~
r Replace One Char
~
55
Deleting Text
Welcome to UNIX
This is an example of
a text file in vi
~ This is an example of
~ a text file in vi
~
~

x Delete One Char
X Delete Char Before Cursor
dd Delete One Line

 Proceed Any Command with a Number to multiply effect
4x
Delete 4 chars
5dd
Delete 5 lines
3dw
Delete 3 words
56
Undo Changes
Welcome to UIX
Welcome to UNIX
This is an example of
a text file in vi
~ This is an example of
WELcome
~ a text file in vi to UIX 123
~
~ This is an example of
Welcome to UNIX
a text file in vi
~
This is an example of
~
a text file in vi
~
~

x Delete One Char
u Undo Last Change

U Undo All Changes on Line

57
Saving Your Changes
Command Mode
ZZ
:wq
:w data
:q!

Save & Exit vi
Save & Exit vi
Save to a file data
Quit Without Saving Changes

58
UNIX..

59

More Related Content

What's hot (20)

Linux process management
Linux process managementLinux process management
Linux process management
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 
Unix Introduction
Unix IntroductionUnix Introduction
Unix Introduction
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Unix
UnixUnix
Unix
 
Unix ppt
Unix pptUnix ppt
Unix ppt
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Unix ppt
Unix pptUnix ppt
Unix ppt
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
 
Know the UNIX Commands
Know the UNIX CommandsKnow the UNIX Commands
Know the UNIX Commands
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
Unix vs linux
Unix vs linuxUnix vs linux
Unix vs linux
 
Unix operating system
Unix operating systemUnix operating system
Unix operating system
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Linux file system
Linux file systemLinux file system
Linux file system
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 

Viewers also liked

Unix(introduction)
Unix(introduction)Unix(introduction)
Unix(introduction)meashi
 
Unix Command Line Productivity Tips
Unix Command Line Productivity TipsUnix Command Line Productivity Tips
Unix Command Line Productivity TipsKeith Bennett
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02duquoi
 
UNIX and Linux - an introduction by Mathias Homann
UNIX and Linux - an introduction by Mathias HomannUNIX and Linux - an introduction by Mathias Homann
UNIX and Linux - an introduction by Mathias HomannMathias Homann
 
Unix memory management
Unix memory managementUnix memory management
Unix memory managementTech_MX
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Scriptsbmguys
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating Systemsubhsikha
 
Unix Process management
Unix Process managementUnix Process management
Unix Process managementWave Digitech
 
PHP to Python with No Regrets
PHP to Python with No RegretsPHP to Python with No Regrets
PHP to Python with No RegretsAlex Ezell
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The BasicsRanel Padon
 
Basic .Net Training in Hyderabad
Basic .Net Training in HyderabadBasic .Net Training in Hyderabad
Basic .Net Training in HyderabadUgs8008
 
Introduction To Unix
Introduction To UnixIntroduction To Unix
Introduction To UnixCTIN
 

Viewers also liked (20)

Basic Unix
Basic UnixBasic Unix
Basic Unix
 
Unix
UnixUnix
Unix
 
Unix(introduction)
Unix(introduction)Unix(introduction)
Unix(introduction)
 
Unix Command Line Productivity Tips
Unix Command Line Productivity TipsUnix Command Line Productivity Tips
Unix Command Line Productivity Tips
 
Unix - An Introduction
Unix - An IntroductionUnix - An Introduction
Unix - An Introduction
 
UNIX/Linux training
UNIX/Linux trainingUNIX/Linux training
UNIX/Linux training
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
 
QSpiders - Unix Operating Systems and Commands
QSpiders - Unix Operating Systems  and CommandsQSpiders - Unix Operating Systems  and Commands
QSpiders - Unix Operating Systems and Commands
 
UNIX and Linux - an introduction by Mathias Homann
UNIX and Linux - an introduction by Mathias HomannUNIX and Linux - an introduction by Mathias Homann
UNIX and Linux - an introduction by Mathias Homann
 
Unix memory management
Unix memory managementUnix memory management
Unix memory management
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Script
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Unix Training - 1
Unix Training - 1Unix Training - 1
Unix Training - 1
 
Unix Process management
Unix Process managementUnix Process management
Unix Process management
 
PHP to Python with No Regrets
PHP to Python with No RegretsPHP to Python with No Regrets
PHP to Python with No Regrets
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
 
Basic .Net Training in Hyderabad
Basic .Net Training in HyderabadBasic .Net Training in Hyderabad
Basic .Net Training in Hyderabad
 
presentation on Unix basic by prince kumar kushwhaha
presentation on Unix basic by prince kumar kushwhahapresentation on Unix basic by prince kumar kushwhaha
presentation on Unix basic by prince kumar kushwhaha
 
Introduction To Unix
Introduction To UnixIntroduction To Unix
Introduction To Unix
 

Similar to Essential UNIX Commands for Beginners

Chapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix ConceptsChapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix ConceptsMeenalJabde
 
Unix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basiUnix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basiPriyadarshini648418
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritpingchockit88
 
Unit 1-a-brief-history-of-unix-ppt
Unit 1-a-brief-history-of-unix-pptUnit 1-a-brief-history-of-unix-ppt
Unit 1-a-brief-history-of-unix-pptRahul Mashal
 
Terminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partITerminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partIKedar Bhandari
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to UnixSudharsan S
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unixsouthees
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scriptsPrashantTechment
 
Linuxppt
LinuxpptLinuxppt
LinuxpptReka
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structureSreenatha Reddy K R
 
Online Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in HyderabadOnline Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in HyderabadRavikumar Nandigam
 
LINUX
LINUXLINUX
LINUXARJUN
 

Similar to Essential UNIX Commands for Beginners (20)

Chapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix ConceptsChapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix Concepts
 
unix.ppt
unix.pptunix.ppt
unix.ppt
 
Unix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basiUnix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basi
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritping
 
Unit 1-a-brief-history-of-unix-ppt
Unit 1-a-brief-history-of-unix-pptUnit 1-a-brief-history-of-unix-ppt
Unit 1-a-brief-history-of-unix-ppt
 
Unix notes
Unix notesUnix notes
Unix notes
 
Unix environment [autosaved]
Unix environment [autosaved]Unix environment [autosaved]
Unix environment [autosaved]
 
Terminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partITerminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partI
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Unix tutorial-08
Unix tutorial-08Unix tutorial-08
Unix tutorial-08
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scripts
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
Online Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in HyderabadOnline Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in Hyderabad
 
LINUX
LINUXLINUX
LINUX
 

Recently uploaded

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Essential UNIX Commands for Beginners

  • 2. Operating Systems An Operating System controls (manages) hardware and software. provides support for peripherals such as keyboard, mouse, screen, disk drives, … software applications use the OS to communicate with peripherals. The OS typically manages (starts, stops, pauses, etc) applications.
  • 4. • What Is UNIX? UNIX is a computer operating system, a control program that works with users to run programs, manage resources, and communicate with other computer systems. Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser system. Any of these users can also run multiple programs at the same time; hence UNIX is called multitasking. 4
  • 5. Introduction to Unix  Unix was born in 1969 at Bell Laboratories, a research subdivision of American Telephone and Telegraph Company.  Some of the functions of the Unix operating system are: it provides a filing system (write, copy, rename, move files) it provides for the loading and executing of the user programs it provides a communication link between the computer and its accessories (input-output devices as terminals, printers, disks, etc).
  • 6. UNIX  Hardware is surrounded by the operating system software  Operating system is called the system kernel The kernel is the core of an operating system and manages the machine’s hardware resources (including the processor and the memory), and provides and controls the way any other software component can access these resources. The kernel runs with a higher privilege than other programs.  Comes with a number of user services and interfaces Shell Components of the C compiler GUI or Command Line Interface
  • 7. Layers of a UNIX System Hardware Kernel System Calls Shells, ls, cp, etc. Netscape, vi, pine, etc.
  • 8. 8
  • 9. Simple Unix Directory Structure / usr etc local bin ... class u1 home bin home ugrad ... u2 ... var ...
  • 10. Unix File System Top most directory in Unix root usr var etc rdefe Home Directory home jsmith djones data mbox, letter, prog1, prog2 jan feb file1, file2, file3, file4 save lib mbox, jandat info Directory containing all home directories x1, x2, x3, x4 file1, file2, file3, file4 10
  • 11. Unix File System Home Directory Personal Directory to store files Usually the Directory Name = login ID Current Directory after successful login root usr home etc rdefe Home directories for: rdefe, jsmith and djones var jsmith djones data mbox, letter, prog1, prog2 jan feb file1, file2, file3, file4 save lib mbox, jandat info x1, x2, x3, x4 file1, file2, file3, file4 11
  • 12. Introducing UNIX Shells A shell is a UNIX program that interprets the commands you enter from the keyboard 12
  • 13. Choosing Your Shell Shells interpret commands and act as firstclass programming languages A default shell is associated with your account when created – Bash is the default shell in Linux A short list of some UNIX shells: Bourne Cshell Korn Bash 13
  • 14. Logging in to UNIX Log in by entering username and password when UNIX system booted or connected to Enter at prompt (command-line mode) or into login box (GUI mode) You’re at the Shell prompt -- Now commands can be issued at the command prompt 14
  • 15. Entering Commands To interact with UNIX, a command is entered at the command prompt UNIX is case-sensitive and most commands are typed in lower case Two categories of commands User-level: perform tasks System administration: system management 15
  • 16. Unix Commands  passwd : Change your password. This will let you enter a new password. Use a password that is not a real word or name and has numbers or punctuation in it. Usage: #passwd  who  By typing “who” you will get a list with all the people logged in at that moment. The leftmost column shows the terminal at which the person is working, the next column shows the date and the rightmost column shows the computer number (IP number). who am i This Check the current being user.It returns username that you are using. 16
  • 17. Unix commands Passwd command usage: sariyer:~> passwd Changing password for dag. Old password: New passwd: Retype new passwd: sariyer:~> 17
  • 18. Unix Commands  man Show any UNIX command usages. “man command” shows purpose of command, its format, how to specify options and usage examples. We should use “man” to learn more about Unix commands given in this documents. Usage: #man who  cal Shows calendar of the current month. Usage: #cal 18
  • 19. Unix Commands The man program displays the UNIX online reference manual, called the man pages, for help purposes To exit Press “q” 19
  • 21. Unix Commands  ps Show process status. “ps” show processes own by your user. “ps –ax” shows all processes currently running on your server. The output is formatted in columns. First column is process ID, second column is process status and last column is command name. 21
  • 22. Unix Commands  mkdir Create a new directory. “mkdir dirname” will create a new subdirectory called “dirname”. Usage: #mkdir test  rmdir Create a new directory. “rmdir dirname” will remove a subdirectory “dirname”. The directory must be completely empty of files. Usage: #rmdir test 22
  • 23. Unix Commands  cp Copy a file. “cp src dest” will make an exact copy of file “src” , with the name “dest”. If “dest” is a subdirectory name, the command will instead copy file “src” into the subdirectory “dest” and use its original file name.  mv Move (rename) a file. “mv src dest” will move file “src” to file “dest”. If “dest” is a subdirectory name, the command will instead move file into the subdirectory “dest” and use its original file name.  rm Remove (delete) a file.. “rm filename” will delete “filename”. Once it is removed, there is no way to get it back! 23
  • 24. Unix Commands ls List Files & Directories $ ls 198 A aa.bb.cc.dd bin datefile etc mail mbox mbox.old unix $ 24
  • 25. Unix Commands ls -p -p Show Directories $ ls -p 198 A aa.bb.cc.dd bin/ datefile etc/ mail/ mbox mbox.old unix/ $ 25
  • 26. Unix Commands ls [directory1] [directory2] ... List the contents of a directory $ ls -p 198 A aa.bb.cc.dd bin/ datefile etc/ mail/ mbox mbox.old unix/ $ $ ls unix awk.data awk.prg bgraph cpy homework2 homework3 unix2test $ 26
  • 27. Unix Commands ls -s -s Show File Size in Blocks Block Sizes $ ls -s 512 bytes 1024 bytes 2048 bytes total 19 1 198 1A 1 aa.bb.cc.dd 1 bin 1 datefile 1 etc 1 mail 2 mbox 1 unix 27
  • 28. Unix Commands ls -l -l Long Listing $ ls -l total 19 -rw-r--r--rw-r--r-drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x -rw------drwxr-xr-x $ 1 1 2 3 2 2 1 2 rdefe rdefe rdefe rdefe rdefe rdefe rdefe rdefe unix unix unix unix unix unix unix unix 53 62 96 80 64 32 984 144 Sep Sep Sep Aug Aug Sep Sep Aug 12 12 4 29 29 2 12 29 21:46 21:47 20:58 20:54 20:54 1992 21:44 20:54 198 A bin db etc mail mbox unix 28
  • 29. Unix Commands ls -a -a List All Files Include Files That Begin with a ‘.’ Files that begin with a ‘.’ are usually configuration files $ ls -a . .. .profile .sh_history 198 A bin datefile db etc mbox unix $ 29
  • 30. Unix Commands ls -r -r Reverse Sort ls -R -R List Contents of Subdirectories • List files in each subdirectory. • Subdirectories with Subdirectories will also be listed…and so on... $ ls -r unix mbox mail etc db datefile bin A 198 $ 30
  • 31. Unix Commands ls -l -t or ls -lt -t Sort On Modification Time $ ls -lt total 19 -rw-r--r--rw-r--r--rw------drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x $ 1 1 1 2 2 2 3 2 rdefe rdefe rdefe rdefe rdefe rdefe rdefe rdefe unix unix unix unix unix unix unix unix 62 53 984 96 64 144 80 32 Sep Sep Sep Sep Aug Aug Aug Sep 12 12 12 4 29 29 29 2 21:47 21:46 21:44 20:58 20:54 20:54 20:54 1992 A 198 mbox bin etc unix db mail 31
  • 32. Unix Commands or ls -l -t -r ls -ltr -tr Reverse Sort On Modification Time $ ls -ltr total 19 drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x -rw-------rw-r--r--rw-r--r-$ 2 3 2 2 2 1 1 1 rdefe rdefe rdefe rdefe rdefe rdefe rdefe rdefe unix unix unix unix unix unix unix unix 32 80 144 64 96 984 53 62 Sep Aug Aug Aug Sep Sep Sep Sep 2 29 29 29 4 12 12 12 1992 20:54 20:54 20:54 20:58 21:44 21:46 21:47 mail db unix etc bin mbox 198 A 32
  • 33. Unix Commands cat [Filename1] [Filename2] … Concatenate Files Display Files to the Screen Ctrl-s Pause Screen Ctrl-q Unpause Screen $ cat sample.file This is a sample file that i'll use to demo how the pr command is used. The pr command is useful in formatting various types of text files. $ 33
  • 34. Unix commands cat command usage: Prompt Command İf you type this row and then press enter The text indicates what we typed to cat 34
  • 35. Unix Commands more [Filename1] [Filename2] … Display Files to the screen one page at a time $ more largefile This is a sample file that i'll use to demo how the pr command is used. The pr command is useful in formatting various types of text files. --More--(16%)  Spacebar (next page)  b (previous page)  Enter Key (next line)     q (Quit & return to unix) /string (search for string) :n (next file) :p (previous file) 35
  • 36. Unix Commands pr [Filename1] [Filename2] … Format & Display Files to the Screen $ pr sample.file 98-05-22 23:07 sample.file Page 1 This is a sample file that i'll use to demo how the pr command is used. The pr command is useful in formatting various types of text files. $ 36
  • 37. Unix Commands pr -[dn] [Filename1] [Filename2] … -d Double Space Output -n Number Lines $ pr -d sample.file 98-05-22 23:07 sample.file Page 1 $ pr -n sample.file This is a sample file that i'll use to demo how 98-05-22 23:07 the pr command is used. sample.file Page 1 1 This is a sample file that i'll use to demo how the The pr command is useful in formatting 2 pr command is used. 3 The pr command is useful in formatting various types of text files. 4 various types of text files. $ $ 37
  • 38. Unix Commands  grep Search file and print lines that match pattern. “grep pattern filename” will print out each line in file “filename” that contains “pattern”. It is case-sensitive search. 38
  • 39. Unix Commands lpr [Filename1] [Filename2] … Send Files to a Unix Printer No Formatting (page numbers, etc.) $ lpr prog1 mbox $ $ pr sample.file Ideal solution would be to combine the lpr & pr to achieve formatted printed output 98-05-22 23:07 sample.file Page 1 This is a sample file that i'll use to demo how the pr command is used. ... 39
  • 40. Unix Redirection Output Normally Displayed to the Screen is Redirected and Becomes the Input to Another Command $ pr prog1 | lpr $ 40
  • 41. Unix Redirection The Output of One Command can be used as the Input to Another $ pr prog1 | lpr $ Command that generates screen output Command | Command Command that requires input 41
  • 42. Unix Redirection Command | Command | Command ... $ ls | pr | lpr $ Directory Listing Formatted Using pr, Printed on Paper 42
  • 43. Unix Redirection Output Normally Displayed to the Screen Can Be Redirected to a File $ pr prog1 > prog1.pr $ Note: Nothing is displayed to the screen The file prog1.pr contains the output of the pr command 43
  • 44. Unix Redirection Redirecting Output The Output of Command can be saved to a File $ pr prog1 > prog1.pr $ Command that generates screen output Command > File File used to capture (save) screen output Caution: Output File will be erased if it already exists. 44
  • 45. Redirection Examples 1 $ pr data > data.pr $ lpr data.pr 2 $ cal 3 1993 > year Using arguments with redirection 3 $ ls -l data > stuff Using arguments & options with redirection Is the same as $ pr data | lpr 45
  • 46. Redirection Examples 4 $ pr data > lpr 5 $ cat text let > mesg 6 $ pr f1 f2 > f1 1 2 Create the file f1 Erases f1 if it already exists pr f1 and f2, redirect to f1 46
  • 47. Unix Commands  head “head” will display the first ten lines in the listed files. head [- lines] [file1 file2 ... fileN] Any numeric option will be taken as the number of lines to print, so head -15 frog will print the first fifteen lines of the file frog. 47
  • 48. Unix Commands  tail Like head, tail display the last ten lines in the listed files. tail [- lines] [file1 file2 ... fileN] Any numeric option will be taken as the number of lines to print, so tail -15 frog will print the last fifteen lines of the file frog. 48
  • 49. Unix Commands  wc wc (word count) simply counts the number of words, lines, and characters in the file(s). wc [-clw] [file1 file2 ... fileN] The three parameters, clw, stand for character, line, and word respectively, and tell wc which of the three to count. 49
  • 50. Unix Commands  cmp cmp compares two files. cmp is very simple, and merely tells you where the two files first differ. cmp file1 [ file2] 50
  • 51. Unix Commands vi [Filename] Full Screen, Visual Editor Changes Displayed As They Are Made Edits A Copy of the File Changes Must Be Saved $ vi mesg 51
  • 52. Unix Commands Vi Modes Command Mode Start in command mode Every Key Performs an Editing Command Insert Mode Perform Text Entry/Input Insert Mode Command Command Mode Insert Mode ESC Key 52
  • 53. Sample vi Edit Session $ vi mesg      Welcome to UNIX Wnewtextelcome to UNIX This is an example of a text file in vi This is an example of ~ a text file in vi ~ ~ ~ ~ :wq $ Start in Command Mode Press a key for Append After Cursor Command Enter text (Input Mode) Press ESC key (Command Mode) Press :wq followed by Enter key to Save & Exit 53
  • 54. Cursor Positioning Moving the Cursor in Command Mode k Key h l j w b Cntrl-d Cntrl-u Enter G 5G Command Forward One Word Backward One Word Scroll Down Scroll Up Down One Line Go To Last Line Go To Line 5 54
  • 55. Text Input Mode vi Text Input Mode Commands Wnewtextelcome to UNIX a Append After Cursor Welcome to UNIXnewtext This is an example of A Append at End of Line a text file in vi newtextWelcome ~ This is an example ofto UNIX i Insert Before Cursor ~ a text file in vi is an example of ~ ThisnewtextWelcome to UNIX I Insert at Beginning of ~ a text file in vi Line ~ This is an example of newtext ~ a text file in vi O Open New Line Above Cursor Welcome to UNIX ~ o Open New Line Below Cursor ~ This is an example of R Replace Text (typeover) a text file in vi ~ r Replace One Char ~ 55
  • 56. Deleting Text Welcome to UNIX This is an example of a text file in vi ~ This is an example of ~ a text file in vi ~ ~ x Delete One Char X Delete Char Before Cursor dd Delete One Line  Proceed Any Command with a Number to multiply effect 4x Delete 4 chars 5dd Delete 5 lines 3dw Delete 3 words 56
  • 57. Undo Changes Welcome to UIX Welcome to UNIX This is an example of a text file in vi ~ This is an example of WELcome ~ a text file in vi to UIX 123 ~ ~ This is an example of Welcome to UNIX a text file in vi ~ This is an example of ~ a text file in vi ~ ~ x Delete One Char u Undo Last Change U Undo All Changes on Line 57
  • 58. Saving Your Changes Command Mode ZZ :wq :w data :q! Save & Exit vi Save & Exit vi Save to a file data Quit Without Saving Changes 58