Shell Programming
A Necessity for all Programmers
Introduction to Linux and Shell
Nagesh Karmali | Firuza Karmali
Department of Computer Science and Engineering
IIT Bombay
You will learn to ...
• File system
• Architecture of Linux system
• Internal file representation
• Shell
• Applications
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 2/15
Unix System
• Birth: 1970s – AT&T Labs, led by Ken Thompson and Dennis Ritchie
• Written in high level language, typically C
• Easy to read and understand
• Power to provide services in a simple way
• Build complex programs from simpler ones
• Hierarchical file system with efficient implementation
• Support for different file systems
• Every device is treaed as a file
• Multi-user, Multiprocess system
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 3/15
Birth of GNU/Linux
• GNU is a recursive acronym for ”GNU’s Not Unix!”
• Open Source System
• Developed from scratch, using the same principles of Unix
• GNU open source development started in 1984, Free Software Foundation (FSF) by
Richard Matthew Stallman
• Developed central components, forming the largest single contribution to the whole
system
• Linus Torvalds wrote Linux in 1991 and contributed to the Free Software Community
• Many distributions/flavors
• Ubuntu
• Debian
• Fedora
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 4/15
File System
• Organized hierarchically as a tree
• Ability to create and delete files
• Grow dynamically
• Devices/Directories/Files are all
treated as files
• Protection of data
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 5/15
Internal Representation of File – Inode
• Block size = 512 bytes
• Block number address = 32
bits (4 bytes)
• Direct addressing =
12 × 512 = 6KB
• Single indirect =
128 × 512 = 64KB
• Double indirect =
128 × 128 × 512 = 8MB
• Triple indirect =
128×128×128×512 = 1GB
Question: What is the
maximum file size if the block
size is 1KB, 2KB, etc.? Figure: ext2 Inode [2]
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 6/15
Architecture of Linux System
application programs
sh
mv who
Kernel
gcc cp Hardware ls
wc date
[Link]
application programs
Figure: Architecture [1]
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 7/15
Shell
• Command line interpreter
• Uses terminal/console
• Interacts with the Kernel
• Execute commands and scripts
• Navigating directories, opening files, etc.
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 8/15
Types of Shell
• Bourne: First shell 1970
• sh
• bash
• ksh
• zsh
• C
• csh
• tcsh
Note: The course uses Ubuntu OS and bash terminal
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 9/15
Applications
• Day to day usage • System monitoring
• Cron jobs (automating tasks) - backup • Automating the build process
data every night
• Running files in batch mode
• Package installation
• Cloud automation and cloning systems • Linking various programs using pipes and
• Creating system images in the cloud filters
• Database migrations • Scheduling and executing system tasks
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 10/15
Used by
• Users
• Programmers
• System Administrators
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 11/15
First look at the terminal
• Terminal
• Command execution
L
Demo
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 12/15
Now, you can Understand ...
• File system
• Internal file representation
• Architecture of Linux system
• Shell
• Applications
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 13/15
References
[1] Maurice J Bach et al.
The design of the UNIX operating system.
Prentice-Hall Englewood Cliffs, 1986.
[2] timtjtim.
An ext2 inode with indirect and double indirect data blocks visualised.
[Link] CC BY-SA 4.0, via
Wikimedia Commons, 2019.
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 14/15
Thank you
1
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 15/15