Nothing Special   »   [go: up one dir, main page]

Unix Operating System: 1 STC Technologies

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

Unix Operating System

STC Technologies

What is UNIX?

Operating system developed in 1960s.


Multi-user and multi-tasking system.
Made of three parts : Kernel, Shell and
programs.
Everything in UNIX is either a file or a process.
A process is an executing program identified
by a unique PID.
A file is a collection of data.

STC Technologies

Components of UNIX
Hardware

STC Technologies

Shell as an Interpreter
The shell is an ordinary program which interprets the commands
that are typed at the terminal, and translates them into commands
that are understood by the kernel.
These programs are located in individual files in one of the system
directories, such as /bin, /etc, or /usr/bin.
The process of command interpretation by the shell can be
explained as follows:
Reads the command
Searches for and locates the file with that name in the directories
containing utilities.
Loads the utility into memory
Executes the utility
Shell scripts of files with program like commands and structures which is
executed in a shell which normally end with .sh extension

Listing files and directories


Command
ls
ls -a

list files and directories


list all files and directories

match any number of characters

match one character

man command
whatis command
mkdir

Meaning

read the online manual page for a


command
brief description of a command
make a directory

cd directory

change to named directory

cd

change to home-directory

cd ~

change to home-directory

cd ..

change to parent directory


STC Technologies

More File Commands


Command
cp file1 file2

copy file1 and call it file2

mv file1 file2

move or rename file1 to file2

rm file
rmdir directory

remove a file
remove a directory

cat file

display a file

less file

display a file a page at a time

head file

display the first few lines of a file

tail file

display the last few lines of a file

grep 'keyword' file


6

Meaning

search a file for keywords


STC Technologies

Redirection and Piping


Command

Meaning

command > file

redirect standard output to a file

command >> file

append standard output to a file

command < file


command1 |
command2

redirect standard input from a file


pipe the output of command1 to the input of
command2

cat file1 file2 > file0 concatenate file1 and file2 to file0
sort

sort data

STC Technologies

vi (visual editor) and its Commands

Default editor for UNIX.


It is a full screen editor.
Two modes of operation:

Command - causes action to be taken on files.


Insert - entered text is inserted into the file.

STC Technologies

Entry and Exit

To start vi :
Command
vi filename

vi -r filename

To exit vi :

Command
:x<Return>
:wq<Return>

Meaning
edit filename starting at
line 1
recover filename that was
being edited when system
crashed
Meaning
quit vi, writing out modified file to
file named in original invocation
quit vi, writing out modified file to
file named in original invocation

:q<Return>

quit (or exit)

:q!<Return>

quit vi even though latest changes


have not been saved for this vi call

vi

STC Technologies

Cursor Movements
Command

or

<Return>

[or down-arrow] move cursor down one line

[or up-arrow]
or <Backspace> [or leftarrow]
k

or

<Space>
0

move cursor up one line


move cursor left one character

[or right-arrow] move cursor right one character


(zero)
$

move cursor to start of current line


(the one with the cursor)
move cursor to end of current line

:0<Return> or 1G

move cursor to beginning of next word


move cursor back to beginning of
preceding word
move cursor to first line in file

:n<Return> or nG

move cursor to line

w
b

:$<Return> or G
10

Meaning

move cursor to last line in file


STC Technologies

Screen Manipulation
Command

^f
^b
^d
^u
^l
^r

11

Meaning

move forward one screen


move backward one
screen
move down (forward) one
half screen
move up (back) one half
screen
redraws the screen
redraws the screen,
removing deleted lines
STC Technologies

Inserting or Adding Text


Command
u
i
I
a
A
o
O

12

Meaning

UNDO WHATEVER YOU JUST DID; a simple


toggle
insert text before cursor, until <Esc> hit
insert text at beginning of current line,
until <Esc> hit
append text after cursor, until <Esc> hit
append text to end of current line, until
<Esc> hit
open and put text in a new line below
current line, until <Esc> hit
open and put text in a new line above
current line, until <Esc> hit

STC Technologies

Changing Text
Command
r
R

cw

cNw

C
cc

Ncc

13

or

cNc

Meaning
replace single character under cursor (no <Esc>
needed)
replace characters, starting with current cursor
position, until <Esc> hit
change the current word with new text,
starting with the character under cursor, until
<Esc> hit
change N words beginning with character under
cursor, until <Esc> hit;
e.g., c5w changes 5 words
change (replace) the characters in the current
line, until <Esc> hit
change (replace) the entire current line, stopping
when <Esc> is hit
change (replace) the next N lines, starting with
the current line,
stopping when <Esc> is hit
STC Technologies

Deleting Text
delete single character under cursor

delete N characters, starting with


character under cursor
delete the single word beginning
with character under cursor
delete N words beginning with
character under cursor;
e.g., d5w deletes 5 words
delete the remainder of the line,
starting with current cursor position

Nx
dw
dNw
D

Ndd

14

dd

delete entire current line

or

delete N lines, beginning with the


current line;
e.g., 5dd deletes 5 lines

dNd

STC Technologies

Cutting and Pasting Text


yy

Nyy

or
p

15

yNy

copy (yank, cut) the current line into


the buffer
copy (yank, cut) the next N lines,
including the current line, into the
buffer
put (paste) the line(s) in the buffer into
the text after the current line

STC Technologies

Searching Text

16

/string

search forward for occurrence of

?string

search backward for occurrence of

string

in text

string

in text

move to next occurrence of search string

move to next occurrence of search string in


opposite direction

STC Technologies

Determining Line Numbers

:.=
:=
^g

17

returns line number of current line at bottom of


screen
returns the total number of lines at bottom of
screen
provides the current line number, along with the
total number of lines,
in the file at the bottom of the screen

STC Technologies

Saving and Reading Files

:r filename<Return>
:w<Return>
:w newfile<Return>
:12,35w smallfile<Return>
:w! prevfile<Return>

18

read file named filename and insert after


current line
(the line with cursor)
write current contents to file named in
original vi call
write current contents to a new file named
newfile

write the contents of the lines numbered 12


through 35 to a new file named smallfile
write current contents over a pre-existing
file named prevfile

STC Technologies

File system security (access rights)

19

STC Technologies

Changing access rights


Command

Meaning

ls -lag

list access rights for all files

chmod [options] file

change access rights for named file

Symbol

20

Meaning

user

group

other

all

read

write (and delete)

execute (and access directory)

add permission

take away permission

STC Technologies

Processes and Jobs


Command

Meaning

command &

run command in background

^C

kill the job running in the foreground

^Z

suspend the job running in the foreground

bg

background the suspended job

jobs
fg %1

foreground job number 1

kill %1

kill job number 1

ps
kill 26152

21

list current jobs

list current processes


kill process number 26152

STC Technologies

Environment Variables

USER (your login name)


HOME (the path name of your home directory)
HOST (the name of the computer you are
using)
ARCH (the architecture of the computers
processor)
DISPLAY (the name of the computer screen to
display X windows)
PRINTER (the default printer to send print
jobs)
PATH (the directories the shell should search
to find a command)

22

STC Technologies

Shell Variables

pwd (your current working directory)


home (the path name of your home directory)
path (the directories the shell should search to
find a command)
prompt (the text string used to prompt for
interactive commands shell your login shell)

23

STC Technologies

What is a Shell Script?

A Text File

With Instructions

Executable

What is a Shell Script?


$ cat > hello.sh <<MY_PROGRAM
#!/bin/sh
echo Hello, world
MY_PROGRAM
$ chmod +x hello.sh
$ ./hello.sh
Hello, world

NB: The two lines of code can be created through vi editor as well

What is a Shell Script? How To Run


$ cat > hello.sh <<MY_PROGRAM
#!/bin/sh
echo Hello, world
MY_PROGRAM
$ chmod +x hello.sh
$ ./hello.sh
Hello, world

What is a Shell Script? What To Do


$ cat > hello.sh <<MY_PROGRAM
#!/bin/sh
echo Hello, world
MY_PROGRAM
$ chmod +x hello.sh
$ ./hello.sh
Hello, world

What is a Shell Script? Executable


$ cat > hello.sh <<MY_PROGRAM
#!/bin/sh
echo Hello, world
MY_PROGRAM
$ chmod +x hello.sh
$ ./hello.sh
Hello, world

What is a Shell Script? Running it


$ cat > hello.sh <<MY_PROGRAM
#!/bin/sh
echo Hello, world
MY_PROGRAM
$ chmod +x hello.sh
$ ./hello.sh
Hello, world

You might also like