Linux Basics and
Shell Scripting
Rohith Ninan and Akshay Warrier
What Is Linux?
What Is Linux?
● Linux is a family of open-source
operating systems.
● Released in September 17, 1991 by
Linus Torvalds.
● Developed based on the Intel x86
architecture.
● Has been ported to more platforms
than any other operating system.
● Runs on Android, Embedded Systems,
Supercomputers and powers over
96.4% servers of the world.
Linux or GNU/Linux?
Linux or GNU/Linux?
● Operating systems consist of many components
● The kernel provides the most basic level of control over
all of the computer's hardware devices.
● It manages the RAM, the CPU and the devices connected to
it.
Linux or GNU/Linux?
● “Linux” refers to the kernel
● All the supporting system
software and libraries were
provided by the GNU Project.
● GNU Project - Founded by Richard
Stallman, first publicly
announced on September 27,
1983.
● He was the originator of the
many ideas about ‘Free Software’
● The Free Software Foundation
emphasises on the use of
“GNU/Linux” but today most
people simply call it ‘Linux’
How It All Started
How It All Started
Ken Thompson (sitting) and Dennis
Ritchie working together at a PDP-11
>ken thompson, dennis ritchie, douglas
mcilroy, and joe ossanna - exist
>got bored and made unix in 1969 at
at&t bell labs
>completely written in assembly
>dennis realizes “oopsie assembly not very
portable, brb lemme make C”
>starts selling unix as proprietary
product
>unix stonks go brr
>stallman enters the chat
>stallman goes “ples make unix compatible
free software”
>by 1990s most gnu software was complete
but they still needed a kernel
How It All Started
>minix enters the chat
>made by andrew s tanenbaum in 1987
>was made for educational purposes
>its licensing didnt allow it to be
called ‘free software’
>linus exists
>linus sadge
>makes open source and free kernel
>also makes git since that wasnt
enough
How It All Started
Linux Distributions
Linux Distributions
● A Linux distribution (commonly called a distro) is any
operating system that makes use of the Linux kernel
● It can be thought of as the many different flavours it
comes in.
● Each distro is unique and has its own set of philosophies
and communities supporting it.
● Its free and open source nature allows it to be modified
and tailored to different use cases.
Linux Distributions
● Some distros are used for
pen-testing, and some are
tailored to work efficiently
on servers
● While other distros are just
designed for everyday normal
tasks.
Fedora Linux
Pop!_OS
https://upload.wikimedia.org/wikipedia/commons/b/b5/Linux_Distribution_Timeline_21_10_2021.svg
Accurate
description of how
to choose an OS
The UNIX Philosophy
The UNIX philosophy
● All the core UNIX system tools were designed so that they
could operate together.
● Using this philosophy programmers avoided writing some
parts of their program that had already been written by
someone else, and could instead recycle the code.
● This philosophy lives on today in GNU/Linux.
The UNIX philosophy
Monolithic Design
● One big thing
● Does a lot of things
● Does nothing it’s designed to do well
● Difficult to add features without a
design overhaul
Modular Design
● Made up of simple pieces
● Each piece does one thing well
● Every piece is well designed
● Adding features is trivial
The UNIX philosophy
The core UNIX philosophy can be summarised as follows:
● Write programs that Do One Thing And Do It Well (DOTADIW)
● Write programs to work together.
● Write programs to handle text streams, because that is a
universal interface.
Desktop Environments
Desktop Environment
● Components that provides GUI
elements, like toolbar,
wallpaper etc.
● Unlike Windows and MacOS,
Linux has a modular Desktop
Environment, separate from
the OS itself
● Allows extensive
customisation and the
ability to choose a desktop
environment that you like.
GNOME
Popular Desktop Environments
KDE Plasma
MATE LXQt
The Shell
The Shell
● Shell, terminal, console,
command line.
● Olden days of Linux, all you
had to work with was the shell.
● System admins, programmers, and
users all sat at something
called a Linux console
terminal.
● The command line allowed text
input only and could display
only text and rudimentary
graphics output.
Types of Terminals
● Graphical Terminals
Terminal emulators that simulate
working on a console terminal but
within a graphical desktop
window.
● Console Terminals
○ Also called a tty
○ Takes linux out of graphical
mode
○ Emulates the old days of a
Bash
● Bash(Bourne Again Shell), written by Brian Fox for
the GNU Project as a free software replacement for
the Bourne shell.
● Was one of the first programs Linus Torvalds ported
to Linux, alongside GCC.
● The default shell used in many Linux distributions
● Other shells - Zsh and Fish, more feature rich than
bash, provide syntax highlighting, auto-correction
features and have tons of plugins.
The Linux File System
The LINUX File System
● Logical collection of files on a partition or disk
● It manages the file name, file size, creation date, and
much more information about a file.
"On a UNIX system, everything is a file; if something is not
a file, it is a process."
● Just like UNIX, Linux makes no difference between a file
and a directory. A directory is just a file containing
names of other files.
● Programs, services, and input and output devices are also
considered to be files, according to the system.
The LINUX File System
The LINUX File System
Key Features:
● Hierarchical file structure : root directory (/)
● Forward slash (/) in path
● No drive letters
● Case Sensitive
● File Extensions : Not necessary. File type is decoded from
its contents.
● Hidden files - eg configuration file
Basic Linux Commands
ls
cd
pwd
file
touch
mkdir
mv
cp
rm
cat
echo
head/tail
grep
neofetch
top/htop
Environment Variables
Environment Variables
● Defines your Linux shell experience.
● Programs and scripts use environment variables to obtain
system information and store temporary data and
configuration information
● There are two environment variable types in the bash
shell
1. Global Variables
2. Local Variables
Environment Variables
● Global environment variables are visible from the shell
session and from any spawned child subshells.
● Local variables are available only in the shell that
creates them
● printenv, env, echo
● set displays all environment variables
● Global vars - Uppercase
● Local vars - Lowercase
Environment Variables
● A local variable created in parent shell does not pass
down to a child shell
● A local variable set within the child shell doesn’t exist
after a return to the parent shell
● export - exports a local variable as a global variable
● A global variable’s value can be read by a child shell,
but its value can’t be changed even with export.
● unset - remove environment variable
The PATH Environment Variable
● Contains the paths to programs and commands separated
with :
● When a command is entered, the shell searches for the
program in all the paths defined in the PATH variable
● If a new program is installed in a directory not
mentioned in PATH then a new entry needs to be added
● PATH=$PATH:<enter new path>
● The changes made to environment variables don’t persist
between reboots
● .bashrc,.zshrc,.profile
Shell Special Characters
Shell Special Characters
$ variable substitution or expand value of variable
> output redirection
>> output redirection to append
* match any number of characters
? match one character
`cmd`
$(cmd)
execute command cmd
| pipe the output of one command to the input of another
 escape interpretation of a character
Users Groups and
Permissions
Users, Groups and Permissions
● Linux is designed for multiple users to have access to
the same system at the same time
● Managing access to resources is a fundamental task
● Linux divides authorization into two:
1. Ownership
2. Permission
Users, Groups and Permissions
What is a “user”?
Entity that can access the resources of the system.
Types of users:
1. Root user
2. Regular user
3. Service account
A user can belong to one or more groups.
Users, Groups and Permissions
What is a “group”?
● Collection of users.
● Primary group: automatically associated with each user
● A user can also be part of zero or more secondary groups.
● Many distros add the standard user to some useful
secondary groups by default.
Users, Groups and Permissions
Some standard groups:
● sudo
● dialout
● adm
● plugdev
● lpadmin
● audio, video
Users, Groups and Permissions
/etc/passwd
/etc/group
/etc/shadow
Users, Groups and Permissions
Users, Groups and Permissions
File Directory
read read contents
list the contents of the
directory
write modify contents
create, delete and rename
files in the directory
execute run as a program
enter the directory, and
access files and
directories inside
Users, Groups and Permissions
chown,chgrp
chown master file.txt
change owner of file to the user “master”
chown :group1 file.txt
chgrp group1 file.txt
change group owner of file to the group
“group1”
chown master:group1 file.txt
Users, Groups and Permissions
chmod
● Symbolic Mode:
chmod ug+x o-r file.txt
chmod o+w file.txt
● Numeric mode:
chmod 770 file.txt
chmod 644 file.txt
7 rwx 111
6 rw- 110
5 r-x 101
4 r-- 100
3 -wx 011
2 -w- 010
1 --x 001
0 --- 000
Users, Groups and Permissions
Package Managers
Package Managers
● Allows users to install,
remove, upgrade,
configure and manage
software packages on an
operating system.
● May be a graphical or a
command line tool
● Packages used to be built
from source but now
package managers are used
Package Managers
● Packaging formats - .deb,
.rpm, .tar.gz
● Different methods of
install for a distro -
dpkg -i, apt install,
pacman -Syu, dnf install
● Repositories - ensure
integrity and
authenticity using
checksums and digital
signatures
● AUR
● Dependency hell
Everyday stuff
Commonly Used Softwares in Linux
Softwares like...
● Spotify
● Discord
● Visual Studio Code
...are available on Linux.
Open Source softwares like...
● GNU Image Manipulation Program (GIMP), Inkscape, Krita
● LibreOffice, OpenOffice
● GNOME and KDE utilities
● VLC Media Player
● Firefox
...natively support Linux.
WINE
● Wine Is Not an Emulator
● Compatibility layer that allows softwares
developed for Windows to run on Linux
● Can be used to install and run softwares
like
○ Adobe Photoshop
○ MS Office
○ Games
on Linux
Bottles : A modern graphical front-end
for wine
Getting Help
● --help
● man <command>
● Google search
● Online forums:
○ StackOverflow
○ Ubuntu Forums
● wiki.archlinux.org, and similar wikis of other distros
● Blogs like ‘It’s FOSS’
● Reddit
Ricing
Exercises
Clone the repository of AutoJoomer: https://github.com/vishal-lokare/AutoJoomer
“cd” into the repository.
1. List all the files and directories in the directory and save it to a file named "contents".
2. Read the file "contents" using the terminal. You should see the names of files.
3. Now, use the "sort" command to sort the names of files in descending order and save the
output to a file named "contents_desc".
4. Change working directory to “src/pages/login”. Search for files "js" in the name using ls,
grep and pipe (|).
5. Challenging: Change working directory to src/pages/login. Search for "AutoJoomer" in the
contents of all the file in the directory. Hint: Use grep and wildcards.
6. Install neofetch and htop through the terminal. (Use the apt commands if you are on Ubuntu).
7. Search for "scientific calculator" in your package manager (apt, if you are using Ubuntu).
References
● Linux Command Line and Shell Scripting
● Package Managers - It’s Foss
● Users, Groups and Permissions - Medium
● File Permissions - Guru 99

Introduction to Linux

  • 1.
    Linux Basics and ShellScripting Rohith Ninan and Akshay Warrier
  • 2.
  • 3.
    What Is Linux? ●Linux is a family of open-source operating systems. ● Released in September 17, 1991 by Linus Torvalds. ● Developed based on the Intel x86 architecture. ● Has been ported to more platforms than any other operating system. ● Runs on Android, Embedded Systems, Supercomputers and powers over 96.4% servers of the world.
  • 4.
  • 5.
    Linux or GNU/Linux? ●Operating systems consist of many components ● The kernel provides the most basic level of control over all of the computer's hardware devices. ● It manages the RAM, the CPU and the devices connected to it.
  • 6.
    Linux or GNU/Linux? ●“Linux” refers to the kernel ● All the supporting system software and libraries were provided by the GNU Project. ● GNU Project - Founded by Richard Stallman, first publicly announced on September 27, 1983. ● He was the originator of the many ideas about ‘Free Software’ ● The Free Software Foundation emphasises on the use of “GNU/Linux” but today most people simply call it ‘Linux’
  • 7.
    How It AllStarted
  • 8.
    How It AllStarted Ken Thompson (sitting) and Dennis Ritchie working together at a PDP-11 >ken thompson, dennis ritchie, douglas mcilroy, and joe ossanna - exist >got bored and made unix in 1969 at at&t bell labs >completely written in assembly >dennis realizes “oopsie assembly not very portable, brb lemme make C” >starts selling unix as proprietary product >unix stonks go brr >stallman enters the chat >stallman goes “ples make unix compatible free software” >by 1990s most gnu software was complete but they still needed a kernel
  • 9.
    How It AllStarted >minix enters the chat >made by andrew s tanenbaum in 1987 >was made for educational purposes >its licensing didnt allow it to be called ‘free software’ >linus exists >linus sadge >makes open source and free kernel >also makes git since that wasnt enough
  • 10.
    How It AllStarted
  • 11.
  • 12.
    Linux Distributions ● ALinux distribution (commonly called a distro) is any operating system that makes use of the Linux kernel ● It can be thought of as the many different flavours it comes in. ● Each distro is unique and has its own set of philosophies and communities supporting it. ● Its free and open source nature allows it to be modified and tailored to different use cases.
  • 13.
    Linux Distributions ● Somedistros are used for pen-testing, and some are tailored to work efficiently on servers ● While other distros are just designed for everyday normal tasks. Fedora Linux Pop!_OS
  • 14.
  • 15.
  • 16.
  • 17.
    The UNIX philosophy ●All the core UNIX system tools were designed so that they could operate together. ● Using this philosophy programmers avoided writing some parts of their program that had already been written by someone else, and could instead recycle the code. ● This philosophy lives on today in GNU/Linux.
  • 18.
    The UNIX philosophy MonolithicDesign ● One big thing ● Does a lot of things ● Does nothing it’s designed to do well ● Difficult to add features without a design overhaul Modular Design ● Made up of simple pieces ● Each piece does one thing well ● Every piece is well designed ● Adding features is trivial
  • 19.
    The UNIX philosophy Thecore UNIX philosophy can be summarised as follows: ● Write programs that Do One Thing And Do It Well (DOTADIW) ● Write programs to work together. ● Write programs to handle text streams, because that is a universal interface.
  • 20.
  • 21.
    Desktop Environment ● Componentsthat provides GUI elements, like toolbar, wallpaper etc. ● Unlike Windows and MacOS, Linux has a modular Desktop Environment, separate from the OS itself ● Allows extensive customisation and the ability to choose a desktop environment that you like.
  • 22.
  • 23.
  • 24.
    The Shell ● Shell,terminal, console, command line. ● Olden days of Linux, all you had to work with was the shell. ● System admins, programmers, and users all sat at something called a Linux console terminal. ● The command line allowed text input only and could display only text and rudimentary graphics output.
  • 25.
    Types of Terminals ●Graphical Terminals Terminal emulators that simulate working on a console terminal but within a graphical desktop window. ● Console Terminals ○ Also called a tty ○ Takes linux out of graphical mode ○ Emulates the old days of a
  • 26.
    Bash ● Bash(Bourne AgainShell), written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. ● Was one of the first programs Linus Torvalds ported to Linux, alongside GCC. ● The default shell used in many Linux distributions ● Other shells - Zsh and Fish, more feature rich than bash, provide syntax highlighting, auto-correction features and have tons of plugins.
  • 27.
  • 28.
    The LINUX FileSystem ● Logical collection of files on a partition or disk ● It manages the file name, file size, creation date, and much more information about a file. "On a UNIX system, everything is a file; if something is not a file, it is a process." ● Just like UNIX, Linux makes no difference between a file and a directory. A directory is just a file containing names of other files. ● Programs, services, and input and output devices are also considered to be files, according to the system.
  • 29.
  • 30.
    The LINUX FileSystem Key Features: ● Hierarchical file structure : root directory (/) ● Forward slash (/) in path ● No drive letters ● Case Sensitive ● File Extensions : Not necessary. File type is decoded from its contents. ● Hidden files - eg configuration file
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
    Environment Variables ● Definesyour Linux shell experience. ● Programs and scripts use environment variables to obtain system information and store temporary data and configuration information ● There are two environment variable types in the bash shell 1. Global Variables 2. Local Variables
  • 50.
    Environment Variables ● Globalenvironment variables are visible from the shell session and from any spawned child subshells. ● Local variables are available only in the shell that creates them ● printenv, env, echo ● set displays all environment variables ● Global vars - Uppercase ● Local vars - Lowercase
  • 51.
    Environment Variables ● Alocal variable created in parent shell does not pass down to a child shell ● A local variable set within the child shell doesn’t exist after a return to the parent shell ● export - exports a local variable as a global variable ● A global variable’s value can be read by a child shell, but its value can’t be changed even with export. ● unset - remove environment variable
  • 52.
    The PATH EnvironmentVariable ● Contains the paths to programs and commands separated with : ● When a command is entered, the shell searches for the program in all the paths defined in the PATH variable ● If a new program is installed in a directory not mentioned in PATH then a new entry needs to be added ● PATH=$PATH:<enter new path> ● The changes made to environment variables don’t persist between reboots ● .bashrc,.zshrc,.profile
  • 53.
  • 54.
    Shell Special Characters $variable substitution or expand value of variable > output redirection >> output redirection to append * match any number of characters ? match one character `cmd` $(cmd) execute command cmd | pipe the output of one command to the input of another escape interpretation of a character
  • 55.
  • 56.
    Users, Groups andPermissions ● Linux is designed for multiple users to have access to the same system at the same time ● Managing access to resources is a fundamental task ● Linux divides authorization into two: 1. Ownership 2. Permission
  • 57.
    Users, Groups andPermissions What is a “user”? Entity that can access the resources of the system. Types of users: 1. Root user 2. Regular user 3. Service account A user can belong to one or more groups.
  • 58.
    Users, Groups andPermissions What is a “group”? ● Collection of users. ● Primary group: automatically associated with each user ● A user can also be part of zero or more secondary groups. ● Many distros add the standard user to some useful secondary groups by default.
  • 59.
    Users, Groups andPermissions Some standard groups: ● sudo ● dialout ● adm ● plugdev ● lpadmin ● audio, video
  • 60.
    Users, Groups andPermissions /etc/passwd /etc/group /etc/shadow
  • 61.
    Users, Groups andPermissions
  • 62.
    Users, Groups andPermissions File Directory read read contents list the contents of the directory write modify contents create, delete and rename files in the directory execute run as a program enter the directory, and access files and directories inside
  • 63.
    Users, Groups andPermissions chown,chgrp chown master file.txt change owner of file to the user “master” chown :group1 file.txt chgrp group1 file.txt change group owner of file to the group “group1” chown master:group1 file.txt
  • 64.
    Users, Groups andPermissions chmod ● Symbolic Mode: chmod ug+x o-r file.txt chmod o+w file.txt ● Numeric mode: chmod 770 file.txt chmod 644 file.txt 7 rwx 111 6 rw- 110 5 r-x 101 4 r-- 100 3 -wx 011 2 -w- 010 1 --x 001 0 --- 000
  • 65.
    Users, Groups andPermissions
  • 66.
  • 67.
    Package Managers ● Allowsusers to install, remove, upgrade, configure and manage software packages on an operating system. ● May be a graphical or a command line tool ● Packages used to be built from source but now package managers are used
  • 68.
    Package Managers ● Packagingformats - .deb, .rpm, .tar.gz ● Different methods of install for a distro - dpkg -i, apt install, pacman -Syu, dnf install ● Repositories - ensure integrity and authenticity using checksums and digital signatures ● AUR ● Dependency hell
  • 69.
  • 70.
    Commonly Used Softwaresin Linux Softwares like... ● Spotify ● Discord ● Visual Studio Code ...are available on Linux. Open Source softwares like... ● GNU Image Manipulation Program (GIMP), Inkscape, Krita ● LibreOffice, OpenOffice ● GNOME and KDE utilities ● VLC Media Player ● Firefox ...natively support Linux.
  • 71.
    WINE ● Wine IsNot an Emulator ● Compatibility layer that allows softwares developed for Windows to run on Linux ● Can be used to install and run softwares like ○ Adobe Photoshop ○ MS Office ○ Games on Linux Bottles : A modern graphical front-end for wine
  • 72.
    Getting Help ● --help ●man <command> ● Google search ● Online forums: ○ StackOverflow ○ Ubuntu Forums ● wiki.archlinux.org, and similar wikis of other distros ● Blogs like ‘It’s FOSS’ ● Reddit
  • 73.
  • 78.
    Exercises Clone the repositoryof AutoJoomer: https://github.com/vishal-lokare/AutoJoomer “cd” into the repository. 1. List all the files and directories in the directory and save it to a file named "contents". 2. Read the file "contents" using the terminal. You should see the names of files. 3. Now, use the "sort" command to sort the names of files in descending order and save the output to a file named "contents_desc". 4. Change working directory to “src/pages/login”. Search for files "js" in the name using ls, grep and pipe (|). 5. Challenging: Change working directory to src/pages/login. Search for "AutoJoomer" in the contents of all the file in the directory. Hint: Use grep and wildcards. 6. Install neofetch and htop through the terminal. (Use the apt commands if you are on Ubuntu). 7. Search for "scientific calculator" in your package manager (apt, if you are using Ubuntu).
  • 79.
    References ● Linux CommandLine and Shell Scripting ● Package Managers - It’s Foss ● Users, Groups and Permissions - Medium ● File Permissions - Guru 99