5) Unix
5) Unix
5) Unix
UNIX
INDEX
Introduction to UNIX
Unix Architecture
Unix Shell
Unix Commands
Files and Directories
Security
Pipes and Filters
vi editor basics
2
UNIX Introduction
3
3
UNIX Variants
44
UNIX Architecture
PC or Workstation
5 5
Unix Architecture Layers
6 6
Unix Parts
Kernel
Core of the OS – a collection of routines/system calls written in C
Loaded into memory when the system is booted
Communicates with the hardware directly
Shell
Interface between the user and the kernel
Acts as the command interpreter
Forms a simpler version of the command line and communicates with the kernel to see that
command is executed
7
7
UNIX Shell
Welcome to UNIX
Shell Have a nice day!
$ ls
Operating Documents
System Readme.txt
output.file
$ _
8
8
UNIX Shell Types
There are several different shells available for Unix; the most popular are described here
Bourne shell named after S.R. Bourne
This is the original Unix shell written by Steve Bourne of Bell Labs. It is available on all UNIX systems.
This shell does not have the interactive facilities provided by modern shells such as the C shell and Korn
shell.
C shell (csh)
This shell was written at the University of California, Berkeley. It provides a C-like language with which to
write shell script.
TC shell (tcsh)
This shell is available in the public domain. It provides all the features of the C shell together with emacs
style editing of the command line.
Korn shell (ksh)
This shell was written by David Korn of Bell labs. It is now provided as the standard shell on Unix
systems.
9
9
UNIX Command
The syntax of every command entered into the UNIX shell is as follows:
$ prog-name [options] [arguments]
The program name must be first
Case sensitive
Location of the program can be specified
There must be a space between every element of the command-line. Commands like ls-la or cd/
will not run
The options may be specified in a variety of ways. All of the following are synonymous: ls -
lax ls -l -x -a ls –ax -l
Help: man prog-name (For example: man cal)
There are two ways of exiting a (Bourne-compatible) shell:
Typing the exit command
Typing Ctrl-d
10
10
Files and Directories
11
Unix File System
All data in UNIX is organized into files. All files are organized into directories. These directories
are organized into a tree-like structure called the file system.
Ordinary Files: An ordinary file is a file on the system that contains data, text, or program
instructions. In this tutorial, you look at working with ordinary files.
Directories: Directories store both special and ordinary files. For users familiar with
Windows or Mac OS, UNIX directories are equivalent to folders.
Special Files: Some special files provide access to hardware such as hard drives, CD-
ROM drives, modems, and Ethernet adapters. Other special files are similar to aliases or shortcuts
and enable you to access a single file using different names.
12
12
Listing files and directories
When you first login, your current working directory is your home directory. Your home directory
has the same name as your user-name, for example, ee91ab, and it is where your personal files
and subdirectories are saved.
The ls command ( lowercase L and lowercase S ) lists the contents of your current working
directory.
13
13
Files and Directories commands
Displaying contents:
ls command
Syntax: ls [options] [arguments]
Options include:
-l
-c
-r
Arguments are interpreted as names
Navigating:
cd <directory> command
cd command
pwd command
14
14
File names, types and wild cards
File names
Use: a-z A-Z 0-9 . , @ - _ + = :
Avoid: space ~ ` ! # $ % ^ & * ?
( ) ' " [ ] { } ; < > \ |
/
File Types
Wild Cards
* match any characters in the filename(s)
• For example: *.txt mark.* a*b *.*
? match any single character
• For example: c?t fred.???? ????x?
[] match any single character that appears within the brackets
• For example: c[aou]t [a-zA-Z]*.txt [!d]*
15
15
File commands
16
16
Filename conventions
In naming files, characters with special meanings such as / * & % , should be avoided.
Also, avoid using spaces within names. The safest way to name a file is to use only alphanumeric
characters, that is, letters and numbers, together with _ (underscore) and . (dot)
File names conventionally start with a lower-case letter, and may end with a dot followed by a group
of letters indicating the contents of the file.
For example, all files consisting of C code may be named with the ending .c, for example prog1.c .
17
17
Working with Directories
18
18
Security
19
Unix System Security
A core security feature in these systems is the [[File system permissions |permissions]] system.
All files in a typical Unix-style file system have permissions set enabling different access to a file.
Permissions on a file are commonly set using the [[chmod]] command and seen through the [[ls]]
command. For example:
Unix permissions permit different users access to a file. Different ''user groups'' have different
20
20
Unix System Security
-rw-r--r--
File type Access rights of file owner Access rights of everybody else
- regular file
d directory Access rights of group members
b block file
c character file
Permission bits
l symbolic link
r read
p pipe
w write
s socket
x execute (if directory, traverse it)
s setuid, setgid (if directory, files have gid of dir owner)
t sticky bit (if directory, append-only)
slide 21
21
Unix System Security
22
22
Unix System Security
23
23
Pipes and Filters
Pipes & Filters
Filter Processing
cat None
more Pagination
sort Sorting
25
25
Searching for text in files
26 26
vi – Text Editor
27
Understanding vi
ESC
Shell
a, A, i,28I, o, O, s, S, c, C, etc
Basic Editing commands
Any command listed below in blue color can be prefixed with a number n to edit/move n intervals
Commands that take into Insert Mode:
a (i) Append (insert) text after (before) the current cursor
A (I) Append text to the end (beginning) of the line
o (O) Start (open) a new line after (before) the current line
Commands used for basic editing, but do not take into Insert Mode:
x (X) Delete (cut) the char under (before) the cursor
dd Delete (cut) the current line
p Put (paste) the recently deleted text
yy Yank (copy) the current line
rx Replace the current character with x
Other special commands:
u Undo the last command
U Restore the current line to how it was when you arrived on it
. Repeat the last command
29
29
Navigating on current line
Any command listed below in blue color can be prefixed with a number n to move n intervals
PC keyboard special keys (arrow keys, Page Up, End, etc) sometimes work in vi
Moving on the current line
SPACE or l Move ahead one character
BACKSPACE or h Move back one character
$ Move to the last character on the line
^ or 0 Move to the first character on the line
fX Move to (find) the next instance of character X
; Move to the next instance of character X
30 30
Other Navigating commands
32
32
Thank you!
http://wf13.myhcl.com/sites/techceed/index.html
33