unix shell dr. tran, van hoai faculty of computer science and engineering hcmc uni. of technology...

Post on 17-Jan-2016

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

UNIX Shell

Dr. Tran, Van Hoai

Faculty of Computer Science and Engineering HCMC Uni. of Technology

hoai@cse.hcmut.edu.vn

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Where is a shell ?

UsersC programsscripts

Shells & Utilities

ksh, bash,gcc, find

kernel open(), fork(),Exec(),

Hardware

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

What is a shell ?

To users:A user interface to UNIXMany shellsThought harder to use than GUI, but notHarder to learn

And definitionProgram to make the system understand

commands (also called command intepreter)

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Purpose of shell

Interactive use Customization of UNIX session

Environment variablesStartup files

ProgrammingShell scripts: executing a series of commands

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Favourite shells

GNU Project’s Bash (Bourne-Again SHell) (bash)Thompson shell → Bourne shell → BashMost popularCommand-line editing

Korn shell (ksh) “Tenex” C shell (tcsh)

C programming style

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Shell for individual /etc/passwd

hoai:x:556:500:Tran Van Hoai:/home/hoai:/bin/bash

Default shell for interactive use “which” to find a path of a shell

hoai@moon:~> which tcsh

/usr/bin/tcsh

hoai@moon:~> which bash

/bin/bash

“exec” to change shellhoai@moon:~> exec bash

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Interactive use

Command history Command-line editing File/command expansion Job control

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Shell scripting

Script = set of shell and UNIX commandsText fileExecutable program

Automating repetitive task and administrative tools

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Simple commands

Sequence of non-blank arguments separated by blanks or tabs

First argument = name of command

hoai@moon:~> ls -l lib.tar.gz -rwx------ 1 hoai users 80738389 2005-09-27 17:09 lib.tar.gz

command arguments

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Types of arguments

Options/Flags-X or –longname

ParametersStrings, file namesDepends on command

$ tar –c –v –f archive.tar main.c main.h

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Getting help on UNIX

“man”: display manual page Manual entry organization

1. Commands

2. System calls

3. Subroutines

4. Special files

5. File format and conventions

6. Games

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Security fundamentals

Multiple users identified by a number and and namehoai:x:556:500:Tran Van Hoai:/home/hoai:/bin/bash

superuser = (id 0, name root) Set of users can form a group

A user can belong to several groups

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

How are users/groups used?

Used to determine if file or process operations can be performedCan a given file be read? Written to ?Can this program be run?Can I use this piece of hardward?Can I stop a particular running process?

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Example

hoai@moon:~> ls -l lib.tar.gz -rwx------ 1 hoai users 80738389 2005-09-27 17:09 lib.tar.gz

read write execute

Dr. Tran, Van Hoai2010

UN

IX S

hel

l

Unix file system

is NEXT

top related