● 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
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.
● 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
● 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 : &
● 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
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
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 ...