Professional Documents
Culture Documents
7. Introduction to shell.
PRACTICAL-1
AIM: Install Linux on the system dual boot with the windows operating
system.
Hardware Requirements
• Memory is speed, so if we have more RAM we'll thank us for it later. If we are a
power user, 8MB should be more than enough for most applications. If we want
to run XP Window, our system will require at least 8MB of RAM.
• A hard drive with space available for installing Linux. The amount of space
required depends on the amount of software we are installing and how much free
space we wish to leave for us. We can install Linux in very small amounts of disk
space, but a realistic minimum is about 150MB. The complete installation can use
up 250MB, with more useful for data files.
• A Hercules, CGA, EGA, VGA, or Super VGA video card and monitor. In
general, if our video card and monitor work under MS-DOS or Microsoft
Windows, then Linux should be able to use them without any problem.
PROCEDURE: -
/ 400M
/usr 1256M
/swap 512M
/var 400M
whatis
Display short description of commands.
--help
display usage summary and argument list
usage statement that describe the command’s
syntax
and list of options it accepts and what they do.
man
provides the documentation for commands
almost every command has a man “page”
pages are grouped into “chapters”
collectively referred to as Linux manual
info
Similar to man, but often more in-depth
Run info without args to list all pages
Info pages are structured like a website
Each pages is divided into “nodes”
Links to nodes are preceded by “*”
pwd
Displays the absolute path to the current directory
the current working directory is the directory in
which you are working.
cd
cd changes directories to an absolute or relative
path
$ cd /home/Joshua/work
$ cd project/docs
ls
Lists the content of the current directory or a
specified directory
ls without arguments lists files and directory
names in the current directory
ls lists the contents of directory given as an
argument
cp
it coping files and directories
mv
Move and/or rename files and directories
touch
Create empty files or update file timestamps
rm
Use for removing files
mkdir
makes a directory
mkdir dirname
rmdir
Remove an empty directory
cat
Contents of the files are displayed
sequentially with no break
Some useful options use with cat
-A –show all characters. Including control
characters and non printing characters
-b -number each (non-blank) line of output
less
Viewing text page by page
history
Use to see list of “remembered” commands
parameter/variables( $ )
Line substitute the value of the variable in a
command
Pipe( | )
Pipe the standard output of one command in to the
standard input of another command
| command1 | command2
chmod
Use to change the access modes by symbolic method or
numeric method
Where mode is:
2(for write)
1(for execute)
df
reports total kilobytes, kilobytes used, kilobytes free
per file system
-h displays sizes in easier to read units
Du
Reports kilobytes used per directory
also take –h option
PATH
Colon separated list of locations where commands
can be found
Which
Command showing location in the PATH of an
executable
su
Su means switch user .this command is use to change
identities
head
Display few lines of text in a file
tail
Displays last few lines of text in a file
Use –n or --lines to change no. of lines displayed
Use –f option to continue to display the file in “real
time”
wc
“word count” – also count lines and characters
$ wc story.txt
sort
sort text to stdout – original file unchanged
common options
-n numeric sort
uniq
remove successive duplicates lines in a file
can use in conjunction with sort to remove all
duplicates
cut
displays specific columns of file data
find
find [directory…] [criteria…]
ps
display process information
useful options:
-a processes by all user
at
Scheduling a process to execute later
at 7 am Thursday
at now + 5 minutes
at midbight + 23 minutes
cron
this is also used for schedule processes
user need not be logged on
cron jobs are listed in crontab file
must edit and install your crontable file
cron table file cannot be edited directly
edit the file and then install with crontab or
edit the file through crontab
hour 0 – 23
day of month 1 – 31
month 1 – 12
installing and
removing software
rpm –qa
vi editor is similar to a text editor. For text editing, vi uses 24 of the 25 lines that are
normally available in a terminal. The three modes in which vi editor operates for sharing
the workload are explained as below:
1. Command Mode
The default mode of the editor where every key pressed is interpreted as a command to
run on text. You’ll have to be in this mode to copy and delete text. Unnecessary pressing
of [Esc] in this mode sound a beep but also confirms that you are in this mode.
2. Input Mode
Every key pressed after switching to this mode actually shows up as text. This mode is
invoked by pressing key i, a, I, A, o, O, r, R, s, and S. Pressing [Esc] in this mode takes vi
to command mode.
The mode used to handle files (like for saving) and perform substitution (replacing one
string with another). Pressing a : in the Command Mode invokes this mode. You then
enter an ex Mode command followed by [Enter]. After the command is run, you are back
to the default Command Mode.
Common vi Commands
Have a look at this list of common vi commands (there are many more, but these will at
least allow you to get some basic work done). Then we'll do one more exercise before
moving on.
u Undo.
Navigation
k Moves cursor up
Editing Text
Dd Delete a line
yy Copy a line
p Moving text
J Joining lines
PRACTICAL-4
Files an Overview: -
The most basic concept of a file, and one we may already be familiar with from other
computer systems, defines a file as a distinct chunk of information that is found
on our hard drive. Distinct means that there can be many different files, each with
its own particular contents. To keep files from getting confused with each other,
every file must have a unique identity. In Linux, we identify each file by its name
and location. In each location or directory, there can be only one file by a
particular name. So, for instance, if we create a file called novel, and we get a
second great idea, we will either have to call it something different, such as
novel2, or put it in a different place, to keep from overwriting the contents already
in our original novel.
Files can contain various types of information. The following three types will become the
most familiar to us:
• User data: Information that we create and update. The very simplest user data is
plain text or numbers. We learn to create these simple files later. More
complicated user data files might have to be interpreted by another program to
make sense. For instance, a spreadsheet file looks like gibberish if we look at it
directly. To work with a spreadsheet, we have to start up the spreadsheet program
and read in the spreadsheet file.
• System data: Information, often in plain text form, that is read and used by the
Linux system - to keep track of which users are allowed on the system, for
instance. As a system administrator, we are responsible for changing system data
files. For instance, when we create a new user, we modify the file /etc/passwd,
which contains the user information. Ordinary users of the system are usually not
concerned with system data files, except for their private startup files.
• Executable files: These files contain instructions that our computer can perform.
This set of instructions is often called a program. When we tell the computer to
perform them, we're telling it to execute the instructions given to it. To human
eyes, executable files contain meaningless gibberish—obviously our computer
doesn't think the way we do! Creating or modifying executable files takes special
tools. We learn how to use these programming tools in Part V, "Linux for
Programmers."
Filenames
Linux allows filenames to be up to 256 characters long. These characters can be lower-
and uppercase letters, numbers, and other characters, usually the dash (-), the underscore
(_), and the dot (.).
They can't include reserved meta-characters such as the asterisk, question mark,
backslash, and space, because these all have meaning to the shell. We met some meta-
characters when we discussed wildcards.
Directories An Overview
Linux, like many other computer systems, organizes files in directories. We can think of
directories as file folders and their contents as the files. However, there is one
absolutely crucial difference between the Linux file system and an office filing
system. In the office, file folders usually don't contain other file folders. In Linux,
file folders can contain other file folders. In fact, there is no Linux "filing
cabinet"—just a huge file folder that holds some files and other folders. These
folders contain files and possibly other folders in turn, and so on.
Parent Directories and Subdirectories: -
Imagine a scenario in which we have a directory A, which contains another directory B.
Directory B is then a subdirectory of directory A, and directory A is the parent directory
of directory B.
From the root directory, the whole structure of directory upon directory springs and
grows like some electronic elm. This is called a tree structure because, from the single
root directory, directories and subdirectories branch off like tree limbs.
The slash (/) character is used to show files or directories within other directories. For
instance, usr/bin means that bin is found in the usr directory. Note that we can't tell, from
this example, whether bin is a file or a directory, although we know that usr must be a
directory because it holds another item—namely, bin. When we see usr/bin/grep, we
know that both usr and bin must be directories, but again, we can't be sure about grep.
The ls program shows directories with a following /—for example, fido/. This notation
implies that we could have, for instance, fido/file; therefore, fido must be a directory.
The root directory is shown simply by the symbol / rather than mentioned by name. It's
very easy to tell when / is used to separate directories and when it's used to signify the
root directory. If / has no name before it, it stands for the root directory. For example, /usr
means that the usr subdirectory is found in the root directory, and /usr/bin means that bin
is found in the usr directory and that usr is a subdirectory of the root directory.
Remember, by definition the root directory can't be a subdirectory.
The Home Directory: -
Linux provides each user with his or her own directory, called the home directory. Within
this home directory, users can store their own files and create subdirectories. Users
generally have complete control over what's found in their home directories. Because
there are usually no Linux system files or files belonging to other users in our home
directory, we can create, name, move, and delete files and directories as we see fit.
Fortunately, navigating the Linux file system is simple. There are only two commands to
be learned, and one of them has absolutely no options or parameters!
darkstar:~$ pwd
/home/fido
darkstar:~$
This tells you that we're currently in the directory /home/fido. (If we are logged in under
a different user name, we will see that name in place of fido.) This is our home directory.
When we log in, Linux always places us in our home directory.
The letters "pwd" stand for "print working directory." Again, a command's name or
function has been cut down to a few easy-to-type characters. (We will often see the term
current directory used in place of working directory.)
We created a file by typing ls -l /bin > test. Remember, the > symbol means "redirect all
output to the following filename." Note that the file test didn't exist before we typed this
command. When we redirect to a file, Linux automatically creates the file if it doesn't
already exist.
What if we want to type text into a file, rather than some command's output? The quick
and dirty way is to use the command cat.
Creating Directories: -
To create a new directory, use the mkdir command. The syntax is mkdir <name>, where
<name> is replaced by whatever we want the directory to be called. This creates a
subdirectory with the specified name in our current directory:
darkstar:~$ ls
darkstar:~$ ls
The mkdir command is already familiar to us if we have used MS-DOS systems. In MS-
DOS, we can abbreviate mkdir as md. We might think that md would work in Linux,
because, after all, most of the commands we've seen have extremely concise names.
However, Linux doesn't recognize md; it insists on the full mkdir.
If we frequently switch between Linux and MS-DOS, we might want to use mkdir for
both systems. However, be warned that we might start typing other Linux commands in
MS-DOS—for example, typing ls instead of dir!
Now that we know how to create files and directories, it's time to learn how to undo our
handiwork.
To remove (or delete) a file, use the rm command (rm is a very terse spelling of remove).
The syntax is rm <filename>. For instance:
darkstar:~$ rm dead_duck
darkstar:~$ rm /tmp/dead_duck
darkstar:~$ rm *
removes all files from your current directory. (Be careful when using wildcards!)
darkstar:~$ rm /tmp/*duck
Removing Directories: -
The command normally used to remove (delete) directories is rmdir. The syntax is rmdir
<directory>.
Before we can remove a directory, it must be empty (the directory can't hold any files or
subdirectories). Otherwise, we see
rmdir: <directory>: Directory not empty
All Linux files and directories have ownership and permissions. We can change permissions, and
sometimes ownership, to provide greater or lesser access to our files and directories. File
permissions also determine whether a file can be executed as a command.
The -rw-r—r— represents the permissions for the file myfile. The file's ownership includes fido
as the owner and users as the group.
File owners are set up by the system during installation. Linux system files are owned by IDs
such as root, uucp, and bin. Do not change the ownership of these files.
Use the chown (change ownership) command to change ownership of a file. The syntax is chown
<owner> <filename>. In the following example, we change the ownership of the file myfile to
root:
darkstar:~$ ls -l myfile
darkstar:~$ ls -l myfile
-rw-r—r— 1 root users 114 Dec 7 14:31 myfile
To make any further changes to the file myfile, or to chown it back to fido, we must use su or log
in as root.
Files (and users) also belong to groups. Groups are a convenient way of providing access to files
for more than one user but not to every user on the system. For instance, users working on a
special project could all belong to the group project. Files used by the whole group would also
belong to the group project, giving those users special access. Groups normally are used in larger
installations. We may never need to worry about groups.
The chgrp command is used to change the group the file belongs to. It works just like chown.
File Permissions: -
Linux let us specify read, write, and execute permissions for each of the following: the owner,
the group, and "others" (everyone else).
read permission enables us to look at the file. In the case of a directory, it let us list the
directory's contents using ls.
write permission enables us to modify (or delete!) the file. In the case of a directory, we must
have write permission in order to create, move, or delete files in that directory.
execute permission enables you to execute the file by typing its name. With directories, execute
permission enables you to cd into them.
The first character of the permissions is -, which indicates that it's an ordinary file. If this were a
directory, the first character would be d. There are also some other, more exotic classes. These
are beyond the scope of this chapter.
The next nine characters are broken into three groups of three, giving permissions for owner,
group, and other. Each triplet gives read, write, and executes permissions, always in that order.
Permission to read is signified by an r in the first position, permission to write is shown by a w in
the second position, and permission to execute is shown by an x in the third position. If the
particular permission is absent, its space is filled by -.
In the case of myfile, the owner has rw-, which means read and write permissions. This file can't
be executed by typing myfile at the Linux prompt.
The group permissions are r—, which means that members of the group "users" (by default, all
ordinary users on the system) can read the file but not change it or execute it.
File permissions are often given as a three-digit number—for instance, 751. It's important to
understand how the numbering system works, because these numbers are used to change a file's
permissions. Also, error messages that involve permissions use these numbers.
The first digit codes permissions for the owner, the second digit codes permissions for the group,
and the third digit codes permissions for other (everyone else).
The individual digits are encoded by summing up all the "allowed" permissions for that
particular user as follows:
read permission 4
write permission 2
execute permission 1
Therefore, a file permission of 751 means that the owner has read, write and execute permission
(4+2+1=7), the group has read and execute permission (4+1=5), and others have execute
permission (1).
If we play with the numbers, we quickly see that the permission digits can range between 0 and
7, and that for each digit in that range there's only one possible combination of read, write, and
execute permissions.
There are two ways to write the permission specification. One is by using the numeric coding
system for permissions:
darkstar:~$ ls -l myfile
darkstar:~$ ls -l myfile
darkstar:~$ ls -l myfile
This method has the advantage of specifying the permissions in an absolute, rather than relative,
fashion. Also, it's easier to tell someone "Change permissions on the file to seven-five-five" than
to say "Change permissions on the file to read-write-execute, read-execute, read-execute."
We can also use letter codes to change the existing permissions. To specify which of the
permissions to change, type u (user), g (group), o (other), or a (all). This is followed by a + to
add permissions or a - to remove them. This in turn is followed by the permissions to be added or
removed. For example, to add execute permissions for the group and others, we would type
Other ways of using the symbolic file permissions are described in the chmod man page.
Any user who has write permission in a directory can delete files in that directory, whether or not
that user owns or has write privileges to those files. Most directories, therefore, have permissions
set to drwxr-xr-x. This ensures that only the directory's owner can create or delete files in that
directory. It is especially dangerous to give write permission to all users for directories!
This is the root directory. It holds the actual Linux program, as well as subdirectories. Do not
clutter this directory with our files!
/home
This directory holds users' home directories. In other UNIX systems, this can be the /usr or /u
directory.
/bin
This directory holds many of the basic Linux programs. bin stands for binaries, files that are
executable and that hold text only computers could understand.
/usr
This directory holds many other user-oriented directories. Some of the most important are
described in the following sections. Other directories found in /usr include
/usr/bin
/var/spool
This directory has several subdirectories. mail holds mail files, spool holds files to be printed,
and uucp holds files copied between Linux machines.
/dev
Linux treats everything as a file! The /dev directory holds devices. These are special files that
serve as gateways to physical computer components. For instance, if we copy to /dev/fd0, we're
actually sending data to the system's floppy disk. Our terminal is one of the /dev/tty files.
Partitions on the hard drive are of the form /dev/hd0. Even the system's memory is a device!
A famous device is /dev/null. This is sometimes called the bit bucket. All information sent to
/dev/null vanishes—it's thrown into the trash.
/usr/sbin
This directory holds system administration files. If we do an ls -l, we see that we must be the
owner, root, to run these commands.
/sbin
This directory holds system files that are usually run automatically by the Linux system.
/etc
This directory and its subdirectories hold many of the Linux configuration files. These files are
usually text, and they can be edited to change the system's configuration (if we know what we're
doing!).
PRACTICAL-5
Linux is designed to serve many users at the same time as well as provide an interface between
the users and the computer with its storage media, such as hard disks and tapes .Users have their
own shells through which they interact with the operating system .As a system administrator, we
can manage user logins on our system .We can add or remove users, as well as add and remove
groups. A particular user can only access the files created by him. Whereas super user (i.e. root)
can access any file it wants to access. Super user has the unlimited access to all the files, devices,
and programs on the system. Each time when a user logs in, two profile scripts are executed. A
system profile script (located in /etc directory) is the same for every user, and each user has
the .bash_profile script in their home directory. As a super user, we can edit the profile script and
put in any commands we want to execute for each user when he logs in. Following is the list of
some directories related to the users.
Directory Description
/etc/skel Holds the default initialization files for the login shell,such as .bash_profile,
To add, modify, and setting a password of a user following commands are used.
When we add a user, an entry for that user is made in the /etc/passwd file, commonly known as
password file. Each entry takes up one line that has several fields separated by colons. The fields
are as follows:
Field Description
Group ID Number used to identify the group to which the user belongs.
Login shell Shell to run when the user logs in; default shell is /bin/bash.
Options that we can include with the useradd and usermod commands are:
Option Description
-c str Adds a comment to the user’s entryin system password file: /etc/ passwd.
-e mm/dd/yy Set an expiration date for the account (None by default). Specify by
month/day/ year.
-f days Sets the number of days an account remains active after its password expires.
Group Management
To create a new group or to modify the existing groups following commands are used.
The system file that holds the group enteries is /etc/group.The file consists of group records with
one record per line and its fields separated by colons. A group record consists of following fields.
Field Description
Options that we can include with the groupadd and groupmod commands are:
Option Description
-r Creates a system group, one lower than the group minimum specified in
login.defs.
Practical-6
AIM: Create, Remove, and Resize various types of partitions through
GUI as well as command line.
Partitioning is a means to divide a single hard drive into many logical drives. A partition is a
contiguous set of blocks on a drive that are treated as an independent disk. A partition table is an
index that relates sections of the hard drive to partitions.
Partition Types
A partition is labeled to host a certain kind of file system. Such a file system could be the Linux
standard ext2 file system or Linux swap space, or even foreign file systems like (Microsoft)
NTFS or (Sun) UFS. There is a numerical code associated with each partition type. For example,
the code for ext2 is 0x83 and Linux swap is 0x82.
The partition type codes have been arbitrarily chosen (we can't figure out what they
should be) and they are particular to a given operating system. Therefore, it is
theoretically possible that if we use two operating systems with the same hard drive, the
same code might be used to designate two different partition types.
OS/2 marks its partitions with a 0x07 type and so does Windows NT's NTFS. MS-DOS
allocates several type codes for its various flavors of FAT file systems: 0x01, 0x04 and
0x06 are known. DR-DOS used 0x81 to indicate protected FAT partitions, creating a type
clash with Linux/ Minix at that time, but neither Linux/Minix nor DR-DOS are widely
used any more.
Primary Partitions
The number of partitions on an Intel-based system was limited from the very beginning:
The original partition table was installed as part of the boot sector and held space for only
four partition entries. These partitions are now called primary partitions.
Logical Partitions
One primary partition of a hard drive may be sub-partitioned. These are logical partitions.
This effectively allows us to skirt the historical four partition limitation.
The primary partition used to house the logical partitions is called an extended partition
and it has its own file system type (0x05). Unlike primary partitions, logical partitions
must be contiguous. Each logical partition contains a pointer to the next logical partition,
which implies that the number of logical partitions is unlimited. However, Linux imposes
limits on the total number of any type of partition on a drive, so this effectively limits the
number of logical partitions. This is at most 15 partitions total on an SCSI disk and 63
total on an IDE disk.
Swap Partitions
Every process running on our computer is allocated a number of blocks of RAM. These
blocks are called pages. The set of in-memory pages which will be referenced by the
processor in the very near future is called a "working set." Linux tries to predict these
memory accesses (assuming that recently used pages will be used again in the near
future) and keeps these pages in RAM if possible.
If we have too many processes running on a machine, the kernel will try to free up RAM
by writing pages to disk. This is what swap space is for. It effectively increases the
amount of memory we have available. However, disk I/O is very slow compared to
reading from and writing to RAM.
Required Partitioning Software
fdisk utility is used to partition a hard disk of any capacity through command line. Linux
allows only 4 primary partitions and any one partition can be further subdivided to form
any number of logical partitions. Only one of the primary partitions can be sub-divided.
fdisk is started by typing (when logged in as root) fdisk device at the command prompt.
"device" might be like /dev/hda or /dev/sda. The basic fdisk commands we need are:
d – To delete a partition
Changes made to the partition table do not take effect until we issue the write (w)
command.
When a partition is created and changes made to the partition table are saved, then to
activate the partition without rebooting the system, use the command partprobe otherwise
it will be activated automatically after reboot.
After activating the created partition, it must be formatted. To format the partition type
the following commands and press enter.
(1.) mke2fs or mkfs.ext2 – if we want the ext2 file system.
(2.) mke2fs – j or mkfs.ext3 - if we want the ext3 file system (j is for journaling).
The partitioning tool used in Red Hat Linux is Disk Druid. With the exception of certain
esoteric situations, Disk Druid can handle the partitioning requirements for a typical Red
Hat Linux installation.
Partition Fields
Each line in the "Partitions" section represents a disk partition. Each line in this section has
five different fields:
Mount Point: A mount point is the location within the directory hierarchy at which a
volume exists. The volume is said to be mounted at this location. This
field indicates where the partition will be mounted. If a partition exists, but
is "not set" we need to define its mount point. Double-click on the
partition or use the Edit key.
Requested: This field shows the partition's original size. To re-define the size, we must
delete the current partition and recreate it using the Add button.
Actual: This field shows the space currently allocated to the partition.
Type: This field shows the partition's type (such as Linux Native or DOS).
Drive Summaries
Each line in the Drive Summaries section represents a hard disk on our system. Each line
has the following fields:
Total: This field shows the total available space on the hard disk.
Free: This field shows how much of the hard disk's space is still unallocated.
Used: These fields show how much of the hard disk's space is currently allocated to
partitions, in megabytes and percentage.
The Drive Summaries section is displayed only to indicate our computer's disk
configuration. It is not meant to be used as a means of specifying the target hard drive for
a given partition.
Adding Partitions:à To add a new partition, select the Add button. A dialog box will appear
• Mount Point: Highlight and enter the partition's mount point. For example, if this
• partition should be the root partition, enter /; enter /boot for the /boot
o Partition, and so on. We can also use the pull-down menu to choose the
o Correct mount point for our partition.
Size (Megs): Enter the size (in megabytes) of the partition. Note this field starts with a "1"
in it; unless changed we'll end up with a 1 MB partition.
Use remaining space: This check box indicates if the size we entered in the previous field
is to be considered the partition's exact size, or its minimum size.
When selected, the partition will grow to fill all available space on
the hard disk. The partition's size will expand and contract as other
partitions are modified. We can make multiple partitions growable;
if we do, the additional free space will be shared among all
growable partitions.
Partition Type: This field contains a list of different partition types (such as Linux Native
or DOS). Select the appropriate partition type by using the mouse.
Allowable Drives: This field contains a list of the hard disks installed on our system. If a
hard disk's box is highlighted, then a desired partition can be created on
that hard disk. If the box is not checked, then the partition will never be
created on that hard disk. By using different check box settings, we can
direct Disk Druid to place partitions as we see fit, or let Disk Druid
decide where partitions should go.
Ok: Select OK once you're satisfied with the settings, and wish to create the partition.
Removing Partitions: à To delete a partition, select the delete button after selecting the
partition we want to delete or make free. A dialog box will
appear that will confirm the deletion of the selected
partition. If OK is pressed the selected partition will be
removed and If Cancel is pressed the partitions will remain
as it is i.e. partition table will not be altered.
PRACTICAL-7
AIM: Introduction to shell.
Using bash: -
Shells in a Nutshell: -
What is a shell, anyway? It seems to be a word used all the time in Linux, but the exact meaning
is vague for many new users (and some veterans). This section explains exactly what a
shell program is and why it is so important when using Linux.
What Is a Shell?
The shell is a program used to interface between you (the user) and Linux (or, more accurately,
between you and the Linux kernel). Figure 10.1 illustrates the relationship between the user, the
shell, and the Linux kernel. Every command we type at a prompt on your screen is interpreted by
the shell, then passed to the Linux kernel.
The shell is a command-language interpreter. It has its own set of built-in shell commands. The
shell can also make use of all of the Linux utilities and application programs that are available on
the system.
Whenever you enter a command it is interpreted by the Linux shell. For example, when we were
introduced to the Linux file- and directory-manipulation commands, all of the sample commands
entered at the command prompt were interpreted by whichever Linux shell we were using.
Some of the commands, such as the print working directory (pwd) command, are built into the
Linux bash shell. Other commands, such as the copy command (cp) and the remove command
(rm), are separate executable programs that exist in one of the directories in the filesystem. As
the user, we don't know (or probably care) if the command is built into the shell or is a separate
program.
The shell tries to find these application programs by looking in all of the directories that are in
your search path. The path is a list of directories where executable programs can be found. If the
command that was entered is not an internal shell command and it is not an executable file in
your path, an error message will be displayed.
As the last step in a successful command, the shell's internal commands and all of the application
programs are eventually broken down into system calls and passed to the Linux kernel.
Another important aspect of the shell is that it contains a very powerful interpretive
programming language. This language is similar in function to the MS-DOS interpreted
language, but is much more powerful. The shell programming language supports most of the
programming constructs found in high-level languages, such as looping, functions, variables, and
arrays.
Each user on our system has a default shell. The default shell for each user is specified in the
system password file, called /etc/passwd. The system password file contains, among other things,
each person's user ID, an encrypted copy of each user's password, and the name of the program
to run immediately after a user logs into the system. The program specified in the password file
does not have to be one of the Linux shells, but it almost always is.
The Bourne shell was written by Steven Bourne. It is the original UNIX shell and is available on
every UNIX system in existence. The Bourne shell is considered to be very good for UNIX shell
programming, but it does not handle user interaction as well as some of the other shells available.
The C shell, written by Bill Joy, is much more responsive to user interaction. It supports features
such as command-line completion that are not in the Bourne shell. The C shell's programming
interface is thought by many not to be as good as that of the Bourne shell, but it is used by many
C programmers because the syntax of its programming language is similar to that of the C
language. This is also why it is named the C shell.
The Korn shell (ksh) was written by Dave Korn. He took the best features of both the C shell and
the Bourne shell and combined them into one that is completely compatible with the Bourne
shell. ksh is efficient and has both a good interactive interface and a good programming
interface.
In addition to these shells, many other shell programs took the basic features from one or more of
the existing shells and combined them into a new version. The three newer shells are tcsh (an
extension of csh), the Bourne Again Shell (bash, an extension of sh), and the Public Domain
Korn Shell (pdksh, an extension of ksh). Bash is the default shell on most Linux systems.
The Bourne Again Shell (bash), as its name implies, is an extension of the Bourne shell. bash is
fully backward-compatible with the Bourne shell, but contains many enhancements and extra
features that are not present in the Bourne shell. bash also contains many of the best features that
exist in the C and Korn shells. bash has a very flexible and powerful programming interface, as
well as a user-friendly command interface.
Why use bash instead of sh? The biggest drawback of the Bourne shell is the way that it handles
user input. Typing commands into the Bourne shell can often be very tedious, especially if we
are using it on a regular basis and typing in a large number of commands. bash provides several
features that make entering commands much easier.
PRACTICAL-8
read n
j=0
i=1
while [ $i -le $n ]
do
j=`expr $j + $i`
i=`expr $i + 1`
done
[root@localhostprog]#
# Program to check whether the given number is a prime or not.
clear
read num
i=2
do
then
break
fi
i=`expr $i + 1`
done
if [ $i -eq $num ]
then
fi
[root@localhost mm]#
# Program to find the factorial of a Number.
clear
read n
prod=1
i=2
if [ $n -gt 1 ]
then
while [ $i -le $n ]
do
i=`expr $i + 1`
done
else
fi
factorial of 5 is 120
[root@localhostmm]#
# Program that works like a five function calculator.
clear
ch='y'
do
echo
read op
echo
read a
read b
echo
if [ $op -eq 1 ]
then
c=$(($a + $b))
then
c=$(($a - $b))
then
c=$(($a * $b))
then
c=$(($a / $b))
then
c=$(($a % $b))
else
fi
read ch
done
Menu is shown below:
1. ADDITION
2. SUBTRACTION
3. MULTIPLICATION
4. DIVISION
5. MODE
multiplication = 90
mod = 4
[root@localhost mm]#