Professional Documents
Culture Documents
Purnima Talukdar
5th January 2012
Agenda
Unix Overview
2
Unix Operating System Structure
Application Programs
Shell
Kernel
Hardware
3
Kernel
4
Shell
Command interpreter
5
File System
Easy to manage.
Types:
ordinary file (stores info)
6
UNIX: Multi-user Multi-tasking
More than one user can run at the same time and more than
one task can run at the same time
7
Unix Process
Login process
check password with the uid
8
Shell: Command Interpreter
Bourne Shell: the default shell (sh)
original unix shell
very efficient
Example
ls [-alRF…] file-list
12
On-line Documentation
For shell command, system programs, and library functions.
%man -k <keywords>
Synopsis
Files
See Also
Bugs
13
I/O Redirection
E.g. who | wc
14
File Name Expansion
\ escape
15
File Name Expansion
ls *.c ls c*2
ls ??? cd ~foo
ls *
16
Filters
ls | wc
17
Command Alias
18
Unix File Systems
Directory
A file that contains information for files
19
Unix File System Road Map
20
Symbolic Links
ln oldfile newfile
21
Permissions
user group others #links owner size (time of last mod) (file name)
22
Chmod
rwx = 4+2+1=7
– Example: chmod 755 Load.sh
23
Pathnames
sue
.. Parent directory
ls ./email
docs email
cd ..
ls ../fred
f1 f2
24
Basic Commands ...
ls [-alrtRF…] <file-list>
a for listing all files including the dot files
l for long format; r for sort in reverse order; t for sort by time
– date ‘+%Y%m%d_%H%M%S’
Guess?
27
Useful Commands
wc [-lwc] <file-list>
Count the number of lines, words and charaters in a file
more <file-list>
Browse through text files one page at a time.
Example:
%tail +5 result.dat # display the last parf of result.dat starting from line 5
%tail -f result.dat # wait and display the new lines appended to result.dat
%tail +30 result.dat | head -15 | more #display line 30-45 of result.dat
28
Useful Commands ...(2)
cut -c <list> <file>
Cut out selected charaters or fields from each line of a file
Examples:
-f full listing
29
Useful Commands ...(3)
grep, egrep, fgrep
%grep Unix doc.1 # Display the lines in doc.1 that contains “Unix”
%grep -v Unix doc.1 # Display the lines which do not contain “Unix”
30
Useful Commands ...(4)
sort [-rnuf…] [-o outfile] [<field-list>] [file-list]
sort the files
-r reverse order
%sort +1 list1 # sort list 1 starting from field 2 to the end of the line
%sort -n -o list4 list3 sort list3 numerically and place the output in list4
31
Useful Commands ...(5)
find <dir-name> <exp>
Recursively search the directory tree rooted at <pathname> and find all files
whose names satisfy <exp>
%find . -name \*.doc -print # list all files names ending with .doc
# print the names of the files under /etc/source whose lst access
time was 2 days ago.
# remove the files under the curent directory whose names begin with a lower case
letter.
# remove the object and binary executable files under the root 32
directory which have not be accessed more than 7 days.
Useful Commands ...(6)
df [-k] [path]
displays the amount of free disk space in the filesystem
du [-k] [path]
displays the amount of disk used by a specific directory or its sub-
directories
Example:
– %kill -9 1234 # kill process 1234
33
Useful Commands ...(7)
awk
Most of the time awk is used to extract fields from a text line. The default
field separator is space. To specify a different one use the option -F.
Example
34
Useful Commands ...(8)
Sed
Sed has several commands, but most people only learn the substitute
command: s. The substitute command changes all occurrences of the
regular expression into a new value.
A simple example is changing "day" in the "old" file to "night" in the "new"
file:
sed s/day/night/ <old >new
s Substitute command
/../../ Delimiter
day Regular Expression Pattern Search Pattern
night Replacement string
35
Useful Commands ...(9)
gzip/gunzip
The following examples illustrate typical uses of the command gzip for
compressing (or "packaging") a file into an "archive file".
gzip archivefile1.txt
This command compresses the file archivefile1.txt and replaces it with the
compressed version named "archivefile1.txt.gz".
If you want to keep the uncompressed version, you can use the -c option,
which writes tostandard out, and then re-direct (">") standard outto a file like
this:
gzip -c archivefile1.txt > archivefile1.txt.gz
36
Useful Commands ...(10)
tar.
Use create compressed archives of directories and files, and also to extract
directories and files from an archive.
Example:
$ tar -tvzf foo.tar.gz
displays the file names in the compressed archive foo.tar.gz while
$ tar -xvzf foo.tar.gz
extracts the files
37
vi Editor - Introduction
Text File Editor
Opening vi editor
vi [+n] filename
Saving a file
:w saves the file without closing it
:w! newfile saves all lines from the entire current file into the file
'newfile', overwriting any existing newfile
38
vi Editor – Insert or Command mode
Insert mode
i insert before the cursor position
Command Mode
Esc will take you to the command mode
vi commands format
[count] command
39
vi Editor
Cursor movement
h moves the cursor 1 space left
j moves the cursor 1 space down
k moves the cursor 1 space up
l moves the cursor 1 space right
^ moves the cursor to the start of the line
$ moves the cursor to the end of the line
b beginning of previous word
w beginning of next word
e end of next word
Control-B moves the cursor one screen backward
Control-F moves cursor one screen forward
G moves the cursor to the end of the file
:n moves the cursor to beginning of line n
40
vi Editor
Basic commands – Deleting Text
x delete single character; 5x deletes 5 characters
C change from cursor to end of line -- delete and start insert mode
J join current line with line that follows (press Enter in insert
mode to split line)
41
vi Editor
Cut, Copy and Paste
yy yank (i.e. copy) one line into a general buffer (5yy to yank 5
lines)
xp Guess?
ddp Guess?
42
vi Editor
Search
/string search down for string
?string search up for string
set commands
:set showmode show when you are in insert mode
:set ic ignore case when searching
:set noic turn ignore case off
:set nu turn on line numbering
:set nonu turn line numbering off
43
Thank You !!!
44