You are on page 1of 19

Chapter 1: Using the Shell

©Copyright Network Development Group 2013.


Three Main OS Components
• Kernel – manages the operation of the
computer
• Shell – provides for interaction between the
user and the computer
• Filesystem – provides a way to organize and
manage all information on the computer’s
disk(s)

©Copyright Network Development Group 2013.


Role of the Kernel
• Main program loaded at startup that manages
the operation of the computer
- Manages devices, memory, and processes
- Handles switching of applications
• Similar to an air traffic controller at an airport

©Copyright Network Development Group 2013.


The Shell
• The shell is a program that allows the user to
type commands, options, and arguments
• Many shell programs exist
• Most popular shell is the “Bash” (Bourne
Again Shell)
• A user’s shell can be changed by the
usermod command by root
• User’s default shell stored in /etc/passwd

©Copyright Network Development Group 2013.


Accessing the Shell
• From a Graphical User Interface (GUI)
- Open a terminal program
• From a Command Line Interface (CLI)
- Provided automatically at login

©Copyright Network Development Group 2013.


The Shell …….. continue
An operating system provides at least one shell or interface; this allows you to tell the computer what to
do. A shell is sometimes called an interpreter because it takes the commands that a user issues and interprets
them into a form that thekernel can then execute on the hardware of the computer. The two most common
types of shells are the Graphical User Interface (GUI) and Command Line Interface (CLI).
Windows® typically use a GUI shell, primarily using the mouse to indicate what you want done. While using
an operating system in this way might be considered easy, there are many advantages to using a CLI,
including:
Command Repetition: In a GUI shell, there is no easy way to repeat a previous command. In a CLI there is
an easy way to repeat (and also modify) a previous command.
Command Flexibility: The GUI shell provides limited flexibility in the way the command executes. In a
CLI, options are specified with commands to provide a much more flexible and powerful
interface.
Resources: A GUI shell typically uses a vast amount of resources (RAM, CPU, etc.). This is because a great
deal of processing power and memory is needed to display graphics. By contrast, a CLI uses
very little system resources, allowing more of these resources to be available to other programs.
Scripting: In a GUI shell, completing multiple tasks often requires multiple mouse clicks. With a CLI,
a script can be created to execute many complex operations by typing just a single "command":
the name of the script. A script is a series of commands placed into a single file. When executed,
the script runs all of the commands in the file.
Remote Access: While it is possible to remotely execute commands in a GUI shell, this feature isn't typically
set up by default. With a CLI shell, gaining access to a remote machine is easy and typically
available by default.
Development: Normally a GUI-based program takes more time for the developers to create when compared
to CLI-based programs. As a result, there are typically thousands of CLI programs on a typical
Linux OS while only a couple hundred programs in a primarily GUI-based OS like Microsoft
Windows®. More programs means more power and flexibility.
©Copyright Network Development Group 2013.
Bash Shell
Not only does the Linux operating system provide multiple GUI shells, multiple CLI
shells are also available. Normally, these shells are derived from one of two older UNIX
shells: The Bourne Shell and the C Shell. In fact, the bash shell derives its name from the
Bourne Shell: Bourne Again SHell. The bash shell has numerous built-in commands and
features that you will learn including:

Aliases: Give a command a different or shorter name to make working with the shell more
efficient.
Re-Executing Commands: To save retyping long command lines.
Wildcard Matching: Uses special characters like ?, *, and [] to select one or more files as a
group for processing.
Input/Output Redirection: Uses special characters for redirecting input, <or <<, and
output, >.
Pipes: Used to connect one or more simple commands to perform more complex operations.
Background Processing: Enables programs and commands to run in the background while
the user continues to interact with the shell to complete other tasks.

©Copyright Network Development Group 2013.


What is a Command?
• A program executed on the command line
• Includes:
- Built-in shell commands
- Binary commands stored in files
- Aliases
- Functions
- Scripts

©Copyright Network Development Group 2013.


Basic Command Syntax
• Syntax: command [options…] [arguments…]
• Commands, options, and arguments are all
case sensitive

©Copyright Network Development Group 2013.


Specifying Options
• Short options are specified with a hyphen and
a single character such as -a or -x
• Short options can be combined: -ax
• Long options are specified with a double
hyphen and a “word”: --all
• Long options can not be combined
• Both short and long options can be used
together

©Copyright Network Development Group 2013.


Specifying Options
• The option “--”, by itself, means “no more
options”
• BSD* style options use no hyphen, just a
single character: i.e. “a”

• *Berkely Standard Distribution (UNIX)

©Copyright Network Development Group 2013.


Specifying Arguments
• Arguments follow options
• Arguments are normally file or directory
names
• Some commands require arguments
• Use single quotes around arguments if they
contain special (non-alphanumeric) characters

©Copyright Network Development Group 2013.


The exec Command
• Takes another command name as an
argument:
$exec ls
• Launches the other command which replaces
the execution of the exec command
• Useful in wrapper scripts
• Also useful for redirection in scripts

©Copyright Network Development Group 2013.


The ls Command
• Display the contents of the current directory
$ls -a displays display all the information
including the hidden files
$ls –l displays the full information in
ascending order.
$ls –s displays the size.
$ls –t displays the time.
$ls –r displays in reverse order.

©Copyright Network Development Group 2013.


The ls Command
You can type the name of a command with multiple short
options. The output of all of these examples is the same, -l will
give a long listing, while -r reverses the display order of the
results:
$ ls -l -r
$ ls -rl
$ ls -lr

©Copyright Network Development Group 2013.


The uname Command
• Displays useful system information:
$uname -s displays kernel name
$uname –p displays processor type
$uname –i displays hardware platform
$uname –m displays machine hardware arch.
$uname –a displays all information

Note : $ !! : it mean execute the last command in the


history

©Copyright Network Development Group 2013.


The pwd Command
• Displays current working directory
$pwd -L displays logical location
$pwd -P displays physical location

The mkdir Command


• Creat a new directory in current location
$mkdir ali : create directory with a name ali
$mkdir –p forth/hiba : create subdirectory in main directory

©Copyright Network Development Group 2013.


The alias Command
• An alias is essentially a nickname for another command or series
of commands. For example, the cal 2017 command will display
the calendar for the year 2017. Suppose you end up running this
command often. Instead of executing the full command each
time, you can create an alias called mycal and run the alias, as
demonstrated in the following graphic:

$alias mycal=“cal 2017”


$mycal :will display the calendar of year 2017

©Copyright Network Development Group 2013.


Command Completion
• Saves time typing large command names
• Start by typing part of command name and
then press the Tab key
• Will complete the rest of the command name
if what has been typed so far is unique
• If not unique, press the tab key a second time.
• Also works to complete file and directory
names when used as arguments

©Copyright Network Development Group 2013.

You might also like