unix shell dr. tran, van hoai faculty of computer science and engineering hcmc uni. of technology...
TRANSCRIPT
![Page 1: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/1.jpg)
UNIX Shell
Dr. Tran, Van Hoai
Faculty of Computer Science and Engineering HCMC Uni. of Technology
![Page 2: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/2.jpg)
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
![Page 3: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/3.jpg)
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)
![Page 4: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/4.jpg)
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
![Page 5: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/5.jpg)
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
![Page 6: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/6.jpg)
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
![Page 7: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/7.jpg)
Dr. Tran, Van Hoai2010
UN
IX S
hel
l
Interactive use
Command history Command-line editing File/command expansion Job control
![Page 8: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/8.jpg)
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
![Page 9: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/9.jpg)
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
![Page 10: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/10.jpg)
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
![Page 11: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/11.jpg)
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
![Page 12: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/12.jpg)
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
![Page 13: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/13.jpg)
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?
![Page 14: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/14.jpg)
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
![Page 15: UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn](https://reader036.vdocuments.net/reader036/viewer/2022082820/5697bf9a1a28abf838c925b3/html5/thumbnails/15.jpg)
Dr. Tran, Van Hoai2010
UN
IX S
hel
l
Unix file system
is NEXT