Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

5) Unix

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

UNIX Basics

UNIX

 INDEX
 Introduction to UNIX
 Unix Architecture
 Unix Shell
 Unix Commands
 Files and Directories
 Security
 Pipes and Filters
 vi editor basics

2
UNIX Introduction

 An operating System is a program that acts as an intermediary between a user of a


computer and the computer hardware.
 It OS executes user programs and make solving user problems easier
 The UNIX operating system is a set of programs that act as a link between the
computer and the user
 A user can also run multiple programs at the same time; hence UNIX is called
multitasking

3
3
UNIX Variants

The table details some of the major variants


UNIX Variant Company
AIX IBM
A/UX Apple
FreeBSD (free) BSD
HP-UX Hewlett-Packard
IRIX Silicon Graphics
Linux (free, PC) Various
NEXT Next
SCO-UNIX (PC) Santa-Cruz
Organisation
Solaris Sun
Ultrix Digital
UnixWare (PC) Novell (now SCO)
QNX (real-time) Quantum Software

44
UNIX Architecture

Five Computers on a Network One Computer with Five Terminals

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

A shell is simply a program that is used to start other programs

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.

 In UNIX there are three basic types of files:

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.

 To find out what is in your home directory, type


% ls

 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

 Display file contents


 cat more head tail
 Comparing file contents
 diff cmp
 Copy files
 cp file1 file2
 cp file1 [… fileN] dir1
 Move and Rename files
 mv file1 file2
 mv file1 [… fileN] dir1
 Delete files
 rm [Options - -i (interactive), -f (force), -r (recursive)]

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

Create Directory : mkdir dir1


Delete directories :rmdir dir1 rm -r
Rename and move directories :Mv
Change directory : cd
Current Directory : (.) means the current directory
Parent Directory : (..) means the parent of the current directory

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:

 -r-xr-xr-x 1 root wheel 745720 May 8 2013 /bin/sh

 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

 File/Directory security information


 User name
 Group name
 Others
 Access privileges on files/directories for:
 Owner of the file
 Any members of the file's group
 Everyone else
 The three permission letters (r, w, and x) mean the following:

Permission For Files For Directories

r read view contents (e.g. ls)

w modify (write) create or delete files

x execute access (e.g. cd)

22
22
Unix System Security

 Changing file permission - chmod (change mode)


Syntax: chmod permissions filename(s)
 Symbolic mode - Permissions are specified by using letters
• Users: u = owner; g = group; o = other; a = all
• Actions: + = Add; - = remove; = set
• Permissions: r = read; w = write; x = execute
 chmod u+w file1
 chmod g-r file1
 Numeric mode - Permissions specified by using three numbers
• Read (r) =4, Write (w) =2 and Execute (x) =1
• For example:
 chmod 640 file1 rw-r-----
 chmod 070 file1 ---rwx---
 Changing file ownership - chown owner filename(s). Ex: chown fred *.doc
 Changing file group - chgrp group filename(s). Ex: chgrp marketing data*

23
23
Pipes and Filters
Pipes & Filters

Two or more programs connected in this way form a pipe.


To make a pipe, put a vertical bar (|) on the command line between two commands.

ls –l > listing who | wc

A filter performs some processing on data it receives from standard


input and produces output. Some of the common filters are:

Filter Processing
cat None

more Pagination

grep Removal of lines that do not contain certain text

sort Sorting

wc Counting of lines, words and/or characters

25
25
Searching for text in files

 grep is used to search for text in files (or Standard Input)


 Syntax:
 grep pattern filename(s)
 Example:
 grep Mark *.txt

26 26
vi – Text Editor

27
Understanding vi

 vi(visual) editor is used to edit text files


 Two modes
 Command mode, where each key typed represents an editing command
 Insert mode, where each key typed (except ESC) represents text that you wish to insert into
the document
 Syntax:
 vi filename(s) or vi

ESC

Shell

Command mode Insert mode

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

 Moving between lines


 ENTER or j or + Move to the next line
 k or - Move to the previous line
 ^f Move forward one page (page down)
 ^b Move back one page (page up)
 ^d Move down half a page
 ^u Move up half a page
 G Go to last line in file
 1G Go to first line in file
 nG Go to line n in file

 Other move commands


 /pattern Move to the next occurrence of pattern
 n (N) Move to the next (previous) occurrence
 w (b) Move forward (back) one word
 % Find the matching bracket: ( ) [ ] and { }
31
31
Quit vi editor

 :w write (save) the file (only if a name has been specified)


 :w file write to the specified file (save as)
 :q quit (only if no changes have been made)
 :wq save and then quit
 :x or ZZ save the file (if changes have been made), then quit
 :q! abandon any changes and quit
 :w! write to a read-only file (that you own)
 :n and :n! open the next file specified on the command line
 :rew rewind to the first file specified on the command line
 :f or ^g display current file details

32
32
Thank you!
http://wf13.myhcl.com/sites/techceed/index.html

33

You might also like