1. Part 1: Shell in Linux
2. Part2: Shell commands
3. Part3: additional commands
4. Part4: Processes
5. Part5: bash code
AGENDA
Shell
The power of Linux
01
● Simply the shell is a program that takes commands
from the user and gives them to the operating
system to perform.
● In other words we can say that, shell is the layer of
programming that understands and executes the
commands a user enters.
● In some systems, the shell is called a command interpreter.
Shell in Linux
Linux User Kernel
Linux User Kernel
SHELL
The Programming interface/Interpreter
Commands
Execute the CMD
Shell in Linux
● There are different flavors of a shell, just as there are different flavors of
operating systems.
● Each flavor of shell has its own set of recognized commands and
functions.
● On most Linux systems a program called bash (which stands for Bourne Again
SHell, an enhanced version of the original Unix shell) program
sh (written by Steve Bourne) acts as the shell program.
● Besides them, there are other shell programs available for Linux
systems. These include: ksh, tcsh and zsh.
User
Application Shell
Low level utilities and modules
Kernel
● Terminal is a program that opens a window and lets you interact with
the shell.
● There are a bunch of different terminal emulators we can use.
● These might include:
○ gnome-terminal
○ Konsole
○ Xterm
○ Rxvt
○ Kvt
○ nxterm
○ eterm.
Terminal
User
Application Shell
Low level utilities and modules
Kernel
Terminal
Shell Commands
Enjoy the power of shell !
02
● Shell is powerful program that allow you to perform a lot of commands
to save your effort, time and many more
● Some of commands we are going to discuss are:
○ Echo
○ > and >>
○ grep
○ Piping “|”
○ Head
○ Tail
○ ; and &&
○ Locate
○ The &
Shell Commands
● Echo command allows you to print out the string or other on the
terminal
● $ echo “Hello .. This is Banhawi”
Shell Commands : Echo
● These two symbols “>” and “>>” let you save the command output into
a file
● The difference between them is:
○ “>” will delete whatever pre-stored in the file and save the new
output into this file
○ “>>” will abend over whatever pre-stored in the file
Shell Commands : > and >>
● Grep command let you filter or search for specific word inside a file
● Suppose you listed /etc subfile and subdirectories and saves it into
Test.txt on the Desktop
● This file contains a huge files and to search for specific file you need to
use “grep” command
Shell Commands : grep
● Piping “|” let you to do another command after the first command be
successfully performed.
● So if you need to list the subdirectories and store it after you can do it
using this command too.
● Thus we can say that piping command always related to the previous
command, it will perform an additional command on the output of the
first command
Shell Commands : piping “|”
● Head command let you view the top lines of any file.
● You can specify number of lines you need to view using the argument
-n
Shell Commands : head
● Tail command let you view the bottom lines of any file.
● You can specify number of lines you need to view using the argument
-n
Shell Commands : tail
● The semicolon “;” and “&&” allow you to do two or more different
command in the same line one after one.
Shell Commands : “;” and &&
● To search for some file or directory, locate is one of the command you
can use to search for this file or directory.
● As we see, we tried to search for the file “rockyou.txt” in the system
and the location is: /usr/share/wordlist/
Shell Commands : locate
● Now suppose you need to perform a command however you know that
this command will take a lot of time to be executed.
● The proper way to do this is to run this command in the background
and here come the power of “&”
● & let you perform your command in the background while you perform
other tasks.
● All you need to do is to type your command and at the very end just
type “&”
Shell Commands : &
● As you can see below after typing the command, a new process
initiated with PID: 2542 to perform this task in the background
● After the task has been finished the terminal notified you with that this
task has been done successfully
● If you need to see the live process
that take a place right now only you
need to type
$ top
Shell Commands : &
Additional
bash
Commands
03
● Now we are going to discuss more commands to use.
● Some of commands we are going to discuss are:
○ wget
○ Sort
○ Cut
Shell Commands
● Wget let you download the index page of any website.
● For example, let’s wget the facebook page
Shell Commands : wget
● Now if you cat the index file that has just downloaded you will see a
huge file
Shell Commands : wget
● Let us grep it to get only facebook.com
● To do it in effective way just type:
$ cat index.html | grep -i -o “facebook.com”
○ -i >> to ignore the case sensitivity
○ -o >> to restrict the output on “facebook.com” only
Shell Commands : wget
● But if you are looking of the subdomains of facebook you need to
retype the command as following:
$ cat index.html | grep -i -o “[a-z0-9]*.facebook.com”
Shell Commands : wget
● As you can see in the previous slide, there are repeated outcomes we
need to eliminate them
● To do so and get only the unique values, use the sort function as
following:
$ cat index.html | grep -i -o “[a-z0-9]*.facebook.com” | sort -u
Shell Commands : sort
● Now suppose you only need the first part of the domain and ignore the
.facebook.com
● To do so, use cut function with the delimiter as following:
$ cat index.html | grep -i -o “[a-z0-9]*.facebook.com” | sort -u | cut -d “.” -f1
Shell Commands : cut
Processes
What is doing behind !
04
More Commands
● Processes in linux is something similar to the task manager in
Windows.
● It shows you the process running in the background with more extra
information
● A lot of commands used for this task:
○ Ps
○ Ps -aux
○ Top
○ htop
Bash scripting
05
Bash Scripting
● In bash scripting you can perform all of the previous tasks and save
them as sh or bash file to be executed automatically once needed.
● Let us try to make our examples ...

Basics of Bash Scripting OVUGUFYYGFCGHKJJJC

  • 1.
    1. Part 1:Shell in Linux 2. Part2: Shell commands 3. Part3: additional commands 4. Part4: Processes 5. Part5: bash code AGENDA
  • 2.
  • 3.
    ● Simply theshell is a program that takes commands from the user and gives them to the operating system to perform. ● In other words we can say that, shell is the layer of programming that understands and executes the commands a user enters. ● In some systems, the shell is called a command interpreter. Shell in Linux
  • 4.
  • 5.
    Linux User Kernel SHELL TheProgramming interface/Interpreter Commands Execute the CMD
  • 6.
    Shell in Linux ●There are different flavors of a shell, just as there are different flavors of operating systems. ● Each flavor of shell has its own set of recognized commands and functions. ● On most Linux systems a program called bash (which stands for Bourne Again SHell, an enhanced version of the original Unix shell) program sh (written by Steve Bourne) acts as the shell program. ● Besides them, there are other shell programs available for Linux systems. These include: ksh, tcsh and zsh.
  • 7.
    User Application Shell Low levelutilities and modules Kernel
  • 8.
    ● Terminal isa program that opens a window and lets you interact with the shell. ● There are a bunch of different terminal emulators we can use. ● These might include: ○ gnome-terminal ○ Konsole ○ Xterm ○ Rxvt ○ Kvt ○ nxterm ○ eterm. Terminal
  • 9.
    User Application Shell Low levelutilities and modules Kernel Terminal
  • 10.
    Shell Commands Enjoy thepower of shell ! 02
  • 11.
    ● Shell ispowerful program that allow you to perform a lot of commands to save your effort, time and many more ● Some of commands we are going to discuss are: ○ Echo ○ > and >> ○ grep ○ Piping “|” ○ Head ○ Tail ○ ; and && ○ Locate ○ The & Shell Commands
  • 12.
    ● Echo commandallows you to print out the string or other on the terminal ● $ echo “Hello .. This is Banhawi” Shell Commands : Echo
  • 13.
    ● These twosymbols “>” and “>>” let you save the command output into a file ● The difference between them is: ○ “>” will delete whatever pre-stored in the file and save the new output into this file ○ “>>” will abend over whatever pre-stored in the file Shell Commands : > and >>
  • 16.
    ● Grep commandlet you filter or search for specific word inside a file ● Suppose you listed /etc subfile and subdirectories and saves it into Test.txt on the Desktop ● This file contains a huge files and to search for specific file you need to use “grep” command Shell Commands : grep
  • 18.
    ● Piping “|”let you to do another command after the first command be successfully performed. ● So if you need to list the subdirectories and store it after you can do it using this command too. ● Thus we can say that piping command always related to the previous command, it will perform an additional command on the output of the first command Shell Commands : piping “|”
  • 20.
    ● Head commandlet you view the top lines of any file. ● You can specify number of lines you need to view using the argument -n Shell Commands : head
  • 21.
    ● Tail commandlet you view the bottom lines of any file. ● You can specify number of lines you need to view using the argument -n Shell Commands : tail
  • 22.
    ● The semicolon“;” and “&&” allow you to do two or more different command in the same line one after one. Shell Commands : “;” and &&
  • 23.
    ● To searchfor some file or directory, locate is one of the command you can use to search for this file or directory. ● As we see, we tried to search for the file “rockyou.txt” in the system and the location is: /usr/share/wordlist/ Shell Commands : locate
  • 24.
    ● Now supposeyou need to perform a command however you know that this command will take a lot of time to be executed. ● The proper way to do this is to run this command in the background and here come the power of “&” ● & let you perform your command in the background while you perform other tasks. ● All you need to do is to type your command and at the very end just type “&” Shell Commands : &
  • 25.
    ● As youcan see below after typing the command, a new process initiated with PID: 2542 to perform this task in the background ● After the task has been finished the terminal notified you with that this task has been done successfully ● If you need to see the live process that take a place right now only you need to type $ top Shell Commands : &
  • 26.
  • 27.
    ● Now weare going to discuss more commands to use. ● Some of commands we are going to discuss are: ○ wget ○ Sort ○ Cut Shell Commands
  • 28.
    ● Wget letyou download the index page of any website. ● For example, let’s wget the facebook page Shell Commands : wget
  • 29.
    ● Now ifyou cat the index file that has just downloaded you will see a huge file Shell Commands : wget
  • 30.
    ● Let usgrep it to get only facebook.com ● To do it in effective way just type: $ cat index.html | grep -i -o “facebook.com” ○ -i >> to ignore the case sensitivity ○ -o >> to restrict the output on “facebook.com” only Shell Commands : wget
  • 31.
    ● But ifyou are looking of the subdomains of facebook you need to retype the command as following: $ cat index.html | grep -i -o “[a-z0-9]*.facebook.com” Shell Commands : wget
  • 32.
    ● As youcan see in the previous slide, there are repeated outcomes we need to eliminate them ● To do so and get only the unique values, use the sort function as following: $ cat index.html | grep -i -o “[a-z0-9]*.facebook.com” | sort -u Shell Commands : sort
  • 33.
    ● Now supposeyou only need the first part of the domain and ignore the .facebook.com ● To do so, use cut function with the delimiter as following: $ cat index.html | grep -i -o “[a-z0-9]*.facebook.com” | sort -u | cut -d “.” -f1 Shell Commands : cut
  • 34.
  • 35.
    More Commands ● Processesin linux is something similar to the task manager in Windows. ● It shows you the process running in the background with more extra information ● A lot of commands used for this task: ○ Ps ○ Ps -aux ○ Top ○ htop
  • 36.
  • 37.
    Bash Scripting ● Inbash scripting you can perform all of the previous tasks and save them as sh or bash file to be executed automatically once needed. ● Let us try to make our examples ...