Instructor Zia Uddin Siddiqui

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 201

INSTRUCTOR

ZIA UDDIN SIDDIQUI



OPERATING SYSTEM
INTRODUCTION
• There are two parts of this Practical Workbook for Operating Systems.
• Part I is introduction to the usage of LINUX Operating System.
• Part II is related to Win32 system programming. This workbook
complements the general information included in Operating Systems
course.
Part I: Linux
• Being one of the few alternatives to Microsoft Operating systems,
Linux has gained wide popularity.
• Linux is freely distributable, efficient, fast operating system that offers
the power of Unix.
• Linux has brought a mini-revolution in the computer world leading to
the acceptance of free software for a wide range of tasks— from
mission-critical websites to corporate information systems
infrastructure to education applications.
Lab sessions
• The first lab session is about installation and introduction to the
major features of Linux.
• Lab sessions 2-3 cover the basic Linux commands.
• Lab 4 is about managing processes.
• Lab sessions 5-8 discuss the major features of the shell, shell scripting
and programming.
• Lab session 9-10 is about simulation of two Operating System‘s
Algorithms in C on Linux.
• Lab sessions 11-12 explain how to recompile the Linux and add
drivers.
Part II: Win32 System Programming
• It contains three Lab sessions that encourage the student to experiment
with Microsoft Windows, without having to work in a raw hardware
environment that offers little or no support.
• The first lab session is an introduction to Windows 2000 internals. Lab
sessions 2-3 are about writing Multiple Process and Multithreaded
Software.
Lab Session 01
• OBJECT
Introduction and Installation of the Linux Operating System
Introduction
• Major features of Linux that helps to get acquainted with them.
• Linux is a clone of the UNIX operating system.
• Linux runs on machines with an Intel 80386 processor or better, as
well as Intel-compatible CPUs, such as AMD and Cyrix.
• Linux is not UNIX, as UNIX is a copyrighted piece of software that
demands license fees when any part of its source code is used.
• Linux was written from scratch to avoid license fees entirely, although
the operation of the Linux operating system is based entirely on
UNIX.
• It shares UNIX's command set and look-and-feel, so if you know
either UNIX or Linux, you know the other, too.
• Linux supports a wide range of software, from TeX (a text formatting
language) to X (a graphical user interface) to the GNU C/C++
compilers to TCP/IP networking.
• Linux is also compliant with the POSIX.1 standard, so porting
applications between Linux and UNIX systems is a snap.
Major Features of Linux
• Full multitasking and 32-bit support.
• Linux, like all other versions of UNIX, is a real multitasking system, allowing
multiple users to run many programs on the same system at once.

• Linux is also a full 32- bit operating system, utilizing the special protected-
mode features of Intel 80386 and later processors and their work-alikes.
Major Features of Linux ….
• The X Window System
• The X Window System is the de facto industry-standard graphics system for
UNIX machines.

• A complete version of the X Window System, known as XFree86, is available


for Linux.

• The X Window System is a very powerful graphics interface, supporting many


applications.
Major Features of Linux ….
• TCP/IP (Transmission Control Protocol/Internet Protocol)
support
• This is the set of protocols that links millions of university and business
computers into a worldwide network known as the Internet.

• With an Ethernet connection, you can have access to the Internet or to a local
area network from your Linux system.

• Using SLIP (Serial Line Internet Protocol) or PPP (Point to Point Protocol),
you can access the Internet over phone lines with a modem.
Major Features of Linux ….
• Virtual memory and shared libraries
• Linux can use a portion of your hard drive as virtual memory, expanding your
total amount of available RAM.

• Linux also implements shared libraries, allowing programs that use standard
subroutines to find the code for these subroutines in the libraries at runtime.

• This saves a large amount of space on your system; each application doesn't
store its own copy of these common routines.
Major Features of Linux ….
• The Linux kernel uses no code from AT&T or any other proprietary source.
• Much of the software available for Linux is free.
• In fact, a large number of utilities in Linux are developed by the GNU
project at the Free Software Foundation in Cambridge, Massachusetts.
• However, Linux enthusiasts, hackers, programmers, and recently even
commercial companies from all over the world have contributed to the
growing pool of Linux software.
• Linux supports (almost) all of the features of commercial versions of UNIX.
In fact, some of the features found in Linux may not be available on other
proprietary UNIX systems.
Major Features of Linux ….
• GNU software support.
• Linux supports a wide range of free software written by the GNU Project,
including utilities such as the GNU C and C++ compiler, gawk, groff, and so
on.

• Many of the essential system utilities used by Linux are GNU software.
Major Features of Linux ….
• Virtual memory support.
• Linux utilizes all of your system's memory, without memory limits or
segmentation through the use of a virtual memory manager.
Major Features of Linux ….
• Built-in support for networking, multitasking, and other features.
• You'll see this touted as "New Technology" in systems such as Windows NT.
In fact, UNIX (and now, Linux) has implemented this "new technology" for
more than 15 years.

• Linux is cheaper to get than most commercially available UNIX systems and
UNIX clones.

• If you have the patience and access to the Internet, the only price you pay for
Linux is your time. Linux is freely available on the Internet.
Major Distributions
• Seven distributions have emerged as most common. These are:

• Red Hat Slackware Caldera


• S.u.S.E
• Debian
• Fedora Core
• BSD or Free BSD
Red Hat
• By most counts, the Red Hat Linux distribution from Red Hat Software
(www.redhat.com) has emerged as the favorite Linux distribution for most
users.

• This distribution is the target, or base, distribution for many commercial


Linux software developers and is the benchmark against which many
distributions are measured.

• Red Hat has gained fame particularly for its tools for installing and
upgrading the operating system and for its well-designed system for
installing, uninstalling, and tracking software application packages.
Installation Procedure
• The first thing to do before you start is to know what hardware is in
the computer you are going to install Linux on.
• You must know at least the manufacturer and model number of
devices such as your monitor, sound card, VGA card.
• This information can be obtained if MS Windows is already installed
on the computer.
• You can collect this information from the MS Windows control panel.
• Some of this information may not be relevant to all installations and
can be ignored.
• Once you know that hardware in your computer, the next step is to
determine how to install the Linux operating system.
• From amongst the various ways to install Linux, the easiest one is
installing from the bootable installation CD- ROMs.
• But a pre-requisite is that your computer must be able to boot from
CD-ROM. Boot sequence can be modified in a computer‘s BIOS.
• If the computer does not permit booting from CD-ROM, one
alternative is to run the autoboot.bat file from the dosutils directory on
the RedHat installation CD.
• Another alternative is to install from a Linux installation boot disk.
• The disk image for the boot disk is available on the images directory
on your RedHat installation CD as boot.img.
• Once you have located the boot image, you need a blank formatted
1.44 MB disk and a disk image utility such as rewrite.
Installation classes
Red Hat Linux provides five different classes, or types, of installations:
• Workstation: A workstation installation is most appropriate if you are
new to the world of Linux, and would like to give it a try. A
workstation installation will create a system for your home or desktop
use. A graphical, Windows-like environment will be installed.
• Server: A server installation is most appropriate if you would like your
system to function as a Linux- based server, and you do not want to
heavily customize your system configuration.
Installation classes….
• Laptop: A laptop installation has been designed to make installing Red
Hat Linux on laptops even easier. Much like a workstation installation,
it will make sure you have the appropriate packages needed, as well as
offer you an automated installation environment.
• Custom: A custom installation allows you the greatest flexibility
during your installation. You choose your boot loader, which packages
you want, and more. Custom installations are most appropriate for
those users more familiar with Red Hat Linux installations and for
those afraid of losing complete flexibility.
Upgrade
• If you already have a version of Red Hat Linux (4.2 or greater)
running on your system and you want to quickly update to the latest
packages and kernel version, then an upgrade is most appropriate for
you.
• These classes give you the option of simplifying the installation
process (with some potential for loss of configuration flexibility), or
retaining flexibility with a slightly more complex installation process.
Workstation Installations
• Most suitable for new users, the workstation installation will install your
choice of the GNOME or KDE desktop environments, or both, and the X
Window System (the graphical software on which the desktop environments
are based).
• Below are the minimum recommended disk space requirements for a
workstation installation where only one language (such as English) will be
installed.
• Workstation choosing GNOME or KDE : 1.5 GB
• Workstation choosing both GNOME and KDE, and games: 1.8 GB
• If you plan to choose all package groups (for example, GNOME is a group
of packages), as well as select additional individual packages, you may
want to allow yourself 2.1 GB or more of disk space.
What a Workstation Installation Will Do
• If you choose automatic partitioning, a workstation installation will
create the following partitions:
• The size of the swap partition is determined by the amount of RAM in
your system and the amount of space available on your hard drive. For
example, if you have 128 MB of RAM then the swap partition created
can be 128 MB – 256 MB (twice your RAM), depending on how
much disk space is available.
• A 50 MB partition mounted as /boot in which the Linux kernel and
related files reside.
• A root partition mounted as / in which all other files are stored (the
exact size of this partition is dependent on your available disk space).
Server Installations
• A server installation is most appropriate for you if you would like your
system to function as a Linux- based server, and you do not want to
heavily customize your system configuration.
• Below are the minimum recommended disk space requirements for a
server installation where only one language (such as English) will be
installed.
• Server (minimum, no graphical interface): 1.3 GB
• Server (choosing everything, no graphical interface): 1.4 GB
• Server (choosing everything, GNOME and KDE): 2.1 GB
Server Installations ….
• If you plan to choose all group packages, as well as select additional
individual packages, you may want to allow yourself 2.3 GB or more
of disk space.
• During the server installation, the X Window System is not configured
and no GUI will be loaded when the system boots, unless you choose
to install the appropriate packages during package selection.
What a Server Installation Will Do
• The size of the swap partition is determined by the amount of RAM in
your system and the amount of space available on your hard drive.
For example, if you have 128 MB of RAM then the swap partition
created can be 128 MB - 256 MB (twice your RAM), depending on
how much disk space is available.
• A 384 MB root partition mounted as /.
• A partition mounted as /usr (the exact size of this partition is
dependent on your available disk space).
• A partition mounted as /home (the exact size of this partition is
dependent on your available disk space).
What a Server Installation Will Do….
• 256 MB partition mounted as /var.
• A 50 MB partition mounted as /boot in which the Linux kernel and
related files are kept.
• This disk partitioning scheme results in a reasonably flexible file
system configuration for most server tasks.
Laptop Installations
• The laptop installation will install your choice of the GNOME or KDE
desktop environments (or both) and the X Window System.
• Below are the minimum recommended disk space requirements for a
laptop installation where only one language (such as English) will be
installed.
• Laptop choosing GNOME or KDE: 1.5 GB
• Laptop choosing both GNOME and KDE: 1.8 GB
Laptop Installations
• If you plan to choose all package groups (for example, GNOME is a
group of packages), as well as select additional individual packages,
you may want to allow yourself 1.7 GB or more of disk space. If you
provide this extra space, you will have room for additional data, if
needed.
What a Laptop Installation Will Do
• If you choose automatic partitioning, a laptop installation will create
the following partitions:
• The size of the swap partition is determined by the amount of RAM in
your system and the amount of space available on your hard drive. For
example, if you have 128 MB of RAM then the swap partition created
can be 128 MB - 256 MB (twice your RAM), depending on how much
disk space is available.
• A 50 MB partition mounted as /boot in which the Linux kernel and
related files reside.
• A root partition mounted as / in which all other files are stored (the
exact size of this partition is dependent on your available disk space).
Custom Installations
• The custom installation allows you the most flexibility during your
installation.
• The workstation and server installations automatically go through the
installation process for you and omit certain steps.
• During a custom installation, you have complete control over the
packages that will be installed on your system.
• The recommended disk space requirements for a custom installation
are as follows:
• Custom (minimum): 350 MB
• Custom (choosing everything): 3.7 GB
What a Custom Installation Will Do
• As you might guess from the name, a custom installation puts the
emphasis on flexibility. You have complete control over which
packages will be installed on your system.
• If you choose automatic partitioning, a custom installation will create
the following partitions:
• The size of the swap partition is determined by the amount of RAM in
your system and the amount of space available on your hard drive.
For example, if you have 128 MB of RAM then the swap partition
created can be 128 MB - 256 MB (twice your RAM), depending on
how much disk space is available.
What a Custom Installation Will Do….
• A 50 MB partition mounted as /boot in which the Linux kernel and
related files reside.
• A root partition mounted as / in which all other files are stored (the
exact size of this partition is dependent on your available disk space).
Recommendation
• We recommend using Custom installation and selecting only the
modules and packages that you need.
• You may delete the existing hard disk partitions in use by MS
Windows and create partitions for Linux from scratch.
• It is also possible to let MS Windows and Linux co-exist and choosing
between them when the computer boots.
• The Red Hat Linux text mode installation program uses a screen-based
interface that includes most of the on-screen "widgets" commonly
found on graphical user interfaces.
• The following screen shots illustrate what you will see.
Lab Session 02

The Installation Procedure


The Installation Procedure….
• The first screen you will see in the installation program is the welcome
screen which does not require any information from the user.
• You just need to press next to continue. The next screen will ask you
to select the language for the installation program. We recommend
selecting English
Figure 1: Installation language selection
dialog
The Installation Procedure….
The next screen will seek the keyboard configuration which is mostly
correctly auto-detected by the installation program so you may not need
to make any changes:
Figure 2: Keyboard type selection dialog
The Installation Procedure….
Next, on the mouse configuration screen, you need to select the kind of
mouse connected to your computer. The common type of mice are serial
or PS-2. PS-2 mice have round connectors whereas serial mice have D-
type connectors, mostly 9-pin. On the next screen you will select the
installation type:
Figure 3: Installation class selection dialog
The Installation Procedure….
Next step is disk partitioning. RedHat Linux installation offers you three
different schemes. We recommend Manually partitioning with Disk
Druid.
Figure 4: Partitioning scheme selection
dialog
Partitioning using Disk Druid
At this point, you must tell the installation program where to install Red
Hat Linux. This is done by defining mount points for one or more disk
partitions in which Red Hat Linux will be installed. You may also need
to create and/or delete partitions at this time.
Figure 5: Partitioning with Disk Druid
Graphical Display of Hard Drive(s)
Disk Druid offers a graphical representation of your hard drive(s). Using
your mouse, click once to highlight a particular field in the graphical
display.
Double-click to edit an existing partition or to create a partition out of
existing free space. Above the display, you will see the drive name
(such as /dev/hda), the geom (which shows the hard disk's geometry and
consists of three numbers representing the number of cylinders, heads,
and sectors as reported by the hard disk), and the model of the hard
drive as detected by the installation program.
Disk Druid's Buttons
These buttons control Disk Druid's actions. They are used to change the
attributes of a partition (for example the file system type and mount
point) and also to create RAID devices. Buttons on this screen are also
used to accept the changes you have made, or to exit Disk Druid. For
further explanation, take a look at each button in order:
• New: Used to request a new partition. When selected, a dialog box
appears containing fields (such as mount point and size) that must be
filled in.
Disk Druid's Buttons…..
• Edit: Used to modify attributes of the partition currently selected in
the Partitions section. Selecting Edit opens a dialog box. Some or all
of the fields can be edited, depending on whether the partition
information has already been written to disk.
• You can also edit free space as represented in the graphical display to
create a new partition within that space. Either highlight the free space
and then select the Edit button, or double-click on the free space to
edit it.
Disk Druid's Buttons…..
• Delete: Used to remove the partition currently highlighted in the
Current Disk Partitions section. You will be asked to confirm the
deletion of any partition.
• Reset: Used to restore Disk Druid to its original state. All changes
made will be lost if you Reset the partitions.
• Make RAID: Make RAID can be used if you want to provide
redundancy to any or all disk partitions. It should only be used if you
have experience using RAID. To make a RAID device, you must first
create software RAID partitions. Once you have created two or more
software RAID partitions, select Make RAID to join the software
RAID partitions into a RAID device.
Partition Fields
Above the partition hierarchy are labels which present information
about the partitions you are creating. The labels are defined as follows:
• Device: This field displays the partition's device name.
• Start: This field shows the sector on your hard drive where the
partition begins.
• End: This field shows the sector on your hard drive where the
partition ends.
• Size: This field shows the partition's size (in MB).
• Type: This field shows the partition's type (for example, ext2, ext3, or
vfat).
Partition Fields
• Mount Point: A mount point is the location within the directory
hierarchy at which a volume exists; the volume is "mounted" at this
location. This field indicates where the partition will be mounted. If a
partition exists, but is not set, then you need to define its mount point.
Double-click on the partition or click the Edit button.
• Format: This field shows if the partition being created will be
formatted.
Recommended Partitioning Scheme
Unless you have a reason for doing otherwise, we recommend that you
create the following partitions:
• A swap partition (at least 32 MB) — swap partitions are used to
support virtual memory. In other words, data is written to a swap
partition when there is not enough RAM to store the data your system
is processing. The size of your swap partition should be equal to twice
your computer's RAM, or 32 MB, whichever amount is larger, but no
more than 2048 MB (or 2 GB). In Disk Druid, the partition field for
swap should look similar to the following:
<Swap> hda6 64M 64M Linux swap
Recommended Partitioning Scheme…..
<Swap> hda6 64M 64M Linux swap
• For example, if you have 1 GB of RAM or less, your swap partition
should be at least equal to the amount of RAM on your system, up to
two times the RAM. For more than 1 GB of RAM, 2 GB of swap is
recommended. Creating a large swap space partition will be especially
helpful if you plan to upgrade your RAM at a later time.
Recommended Partitioning Scheme…..
• A /boot partition (50 MB) — the partition mounted on /boot contains
the operating system kernel (which allows your system to boot Red
Hat Linux), along with files used during the bootstrap process. Due to
the limitations of most PC BIOSes, creating a small partition to hold
these files is a good idea. For most users, a 50 MB boot partition is
sufficient. In Disk Druid, the partition field for /boot should look
similar to:
/boot hda1 50M 50M Linux native
Recommended Partitioning Scheme…..
• A root partition (1.5-3.7 GB) — this is where "/" (the root directory)
will be located. In this setup, all files (except those stored in /boot) are
on the root partition. A 1.5 GB root partition will permit the equivalent
of a workstation installation (with very little free space), while a 3.7
GB root partition will let you install every package. In Disk Druid,
the partition field for / should look similar to:
/ hda5 3734M 3734M Linux native
Adding Partitions
To add a new partition, select the New button. A dialog box appears.
• Mount Point: Enter the partition's mount point. For example, if this
partition should be the root partition, enter/; enter /boot for the /boot
partition, and so on. You can also use the pull-down menu to choose
the correct mount point for your partition.
• File System Type: Using the pull-down menu, select the appropriate
file system type for this partition.
Adding Partitions
• Allowable Drives: This field contains a list of the hard disks installed
on your 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 checkbox settings, you can have Disk Druid place partitions
as you see fit, or let Disk Druid decide where partitions should go.
Figure 6: Creating a New Partition
Adding Partitions ….
• Size (Megs): Enter the size (in megabytes) of the parition. Note, this
field starts with a "1" (one); unless changed, only a 1 MB partition will
be created.
• Additional Size Options: Choose whether to keep this partition at a
fixed size, to allow it to "grow" (fill up the available hard drive space)
to a certain point, or to allow it to grow to fill any remaining hard
drive space available. If you choose Fill all space up to (MB), you
must give size constraints in the field to the right of this option. This
allows you to keep a certain amount of space free on your hard drive
for future use.
Adding Partitions ….
• Force to be a primary partition: Select whether the partition you are
creating should be one of the first four partitions on the hard drive. If
unselected, the partition created will be a logical partition.
• Check for bad blocks: Checking for bad blocks can help prevent data
loss by locating the bad blocks on a drive and making a list of them to
prevent using them in the future. If you wish to check for bad blocks
while formatting each file system, please make sure to select this
option. Selecting Check for bad blocks may dramatically increase
your total installation time. Since most newer hard drives are quite
large in size, checking for bad blocks may take a long time; the length
of time depends on the size of your hard drive.
Adding Partitions ….
• Ok: Select Ok once you are satisfied with the settings and wish to
create the partition.
• Cancel: Select Cancel if you do not want to create the partition.
File System Types
Red Hat Linux allows you to create different partition types, based on the file
system they will use. The following is a brief description of the different file
systems available, and how they can be utilized.
• ext2 — An ext2 file system supports standard Unix file types (regular files,
directories, symbolic links, etc). It provides the ability to assign long file
names, up to 255 characters. Versions prior to Red Hat Linux 7.2 ext2 file
systems by default.
• ext3 — The ext3 file system is based on the ext2 file system and has one
main advantage — journaling. Using a journaling file system reduces time
spent recovering a file system after a crash as there is no need to fsck the
file system. The ext3 file system will selected by default and is highly
recommended.
File System Types….
• software RAID — Creating two or more software RAID partitions
allows you to create a RAID device.
• swap — Swap partitions are used to support virtual memory. In other
words, data is written to a swap partition when there is not enough
RAM to store the data your system is processing.
• vfat — The VFAT file system is a Linux file system that is compatible
with Windows 95/NT long filenames on the FAT file system.
Editing Partitions
• To edit a partition, select the Edit button or double-click on the
existing partition. If the partition already exists on your hard disk, you
will only be able to change the partition's mount point. If you want to
make any other changes, you will need to delete the partition and
recreate it
Deleting a Partition
• To delete a partition, highlight it in the Partitions section and click the
Delete button. You will be asked to confirm the deletion.
Boot Loader Installation
• In order to boot your Red Hat Linux system, after installation, without
a boot disk, you usually need to install a boot loader. You can choose
to install GRUB (selected by default), LILO, or you can choose not to
install a boot loader at all.
• First, select which boot loader you want to install. If you do not want
to overwrite your current boot loader, choose Do not install a boot
loader. If you choose not to install GRUB or LILO for any reason,
you will not be able to boot your Red Hat Linux system directly, and
you will need to use another boot method (such as a boot diskette).
Use this option only if you are sure you have another way of booting
your Red Hat Linux system! We recommend using LILO.
Boot Loader Installation….
• Assuming you chose GRUB or LILO, you must now determine where you
want the boot loader to be installed. You may install the boot loader in one
of two places:
• The master boot record (MBR)
• This is the recommended place to install a boot loader, unless the MBR
already starts another operating system loader, such as System Commander.
The MBR is a special area on your hard drive that is automatically loaded
by your computer's BIOS, and is the earliest point at which the boot loader
can take control of the boot process. If you install it in the MBR, when your
machine boots, GRUB (or LILO) will present a boot prompt. You can then
boot Red Hat Linux or any other operating system that you have configured
the boot loader to boot the first sector of your boot partition
Figure 7: Boot Loader Installation
Boot Loader Installation….
• This is recommended if you are already using another boot loader on
your system. In this case, your other boot loader will take control first.
You can then configure that boot loader to start GRUB (or LILO),
which will then boot Red Hat Linux.

• If your system will use only Red Hat Linux, you should choose the
MBR. For systems with Windows 95/98, you should also install the
boot loader to the MBR so that it can boot both operating systems. In
short, we recommend using the MBR method.
Boot Loader Installation….
• If you wish to add default options to GRUB or LILO's boot command,
enter them into the Kernel parameters field. Any options you enter
will be passed to the Linux kernel every time it boots. This is generally
not needed except for a few complex situations.

• The Force use of LBA32 (not normally required) option allows you
to exceed the 1024 cylinder limit for the /boot partition. If you have a
system which supports the LBA32 extension for booting operating
systems above the 1024 cylinder limit, and you want to place your
/boot partition above cylinder 1024, you should select this option.
Boot Loader Installation….
• Every bootable partition is listed, including partitions used by other
operating systems. The partition holding your Red Hat Linux system's
root file system will have a Boot label of Red Hat Linux (for GRUB)
or linux (for LILO). Other partitions may also have boot labels. If you
would like to add boot labels for other partitions (or change an existing
boot label), click once on the partition to select it. Once selected, you
can change the boot label by editing the name in the Boot label text
field. The Boot label column lists what you must enter at the boot
prompt, in non-graphical boot loaders, in order to boot the desired
operating system.
Boot Loader Installation….
• Once you have loaded the GRUB boot screen, use the arrow keys to
choose a boot label or type e for edit. You will be presented with a list
of items in the configuration file for the boot label you have selected.

• At the graphical LILO screen, press [Ctrl]-[x] to exit to the boot:


prompt. If you forget the boot labels defined on your system, you can
always press [Tab] at the prompt to display a list of defined boot
labels.
Network Configuration
• If you have multiple devices, you will see a tab for each device. You
may switch between devices (for example, between eth0 and eth1) and
the information you provide on each tab will be specific to each
device.
Figure 8: Network Configuration
Network Configuration
• You can indicate if you would like to configure your IP address using
DHCP (Dynamic Host Configuration Protocol). If you select Activate
on boot, your network interface will be started when you boot. We
will not use DHCP, so you need to provide the IP address, netmask,
network address and broadcast address as provided on the small label
on the PC. The remaining entries can be skipped.

Firewall Configuration
• The next screen will ask you to configure the type of firewall to use.
There will be three options, namely, high, medium, and no firewall.
You can also customize these. However, we recommend selecting no
firewall. Selecting a firewall type will deny access to certain network
services to and from the host.
Firewall Configuration….
• High
If you choose High, your system will not accept connections (other than
the default settings) that are not explicitly defined by you. By default,
only the following connections are allowed:
• DNS replies
• DHCP — so any network interfaces that use DHCP can be properly
configured
Firewall Configuration….
If you choose High, your firewall will not allow the following:
• Active mode FTP (passive mode FTP, used by default in most clients,
should still work)
• IRC DCC file transfers
• Real AudioTM
• Remote X Window System clients
If you are connecting your system to the Internet, but do not plan to run
a server, this is the safest choice. If additional services are needed, you
can choose Customize to allow specific services through the firewall.
Firewall Configuration….
• Medium
If you choose Medium, your firewall will not allow remote machines to have
access to certain resources on your system. By default, access to the
following resources are not allowed:
• Ports lower than 1023 — the standard reserved ports, used by most system
services, such as FTP, SSH, telnet, HTTP, and NIS.
• The NFS server port (2049) — NFS is disabled for both remote severs and
local clients.
• The local X Window System display for remote X clients.
• The X Font server port (by default, xfs does not listen on the network; it is
disabled in the font server).
Firewall Configuration….
• If you want to allow resources such as RealAudioTM while still blocking
access to normal system services, choose Medium. Select Customize to
allow specific services through the firewall.
• Obviously, since we will be configuring some of these servers in later labs,
we would not want to deny access to any of them.
• The next step, Language support selection has the necessary support
checked already so we will not need to do anything special there. Click next
to go on to time zone selection. On the time zone selection screen, you will
see a map of the world and can select your location from either the
scrollable list box or by clicking on locations marked by yellow dots on the
map. Our location is Karachi, Islamabad, and we are GMT+5:00.
Firewall Configuration….
• Clicking next will bring you to the user account configuration screen.
You need to provide a password for the super user account, root,
which is the Linux equivalent of the Windows NT administrator user
account. The password must be typed twice. Since it is not echoed on
the screen, just to be sure that you did not misspell anything, you are
not very likely to mistype something exactly the same way twice. The
root password needs to be at least six characters long. For your
installation we recommend using cnl2k3 as the root password for
uniformity.
Firewall Configuration….
• On this screen you can also create other user accounts. You are
welcome to create user accounts for your ordinary use. Even if you
know the root account password, it is not a good practice to log on
using it. Log on with an ordinary user account and do your work. If
and when you need root privileges, switch to root mode by issuing the
command su. Linux will ask you for the root password and if you type
the correct password, put you in super user mode. Once you are done
doing whatever needed root privileges, such as installing a program
from an RPM, switch back to ordinary user mode by typing exit.
When you are done on this screen, click next.
Figure 9: Package Selection Screen
Firewall Configuration….
• Everything on the authentication configuration screen is already set to
acceptable values for us, so we will just click next on that screen.
Since we chose the custom installation class, the next screen is
package group selection. The last item in this list is ―Everything.‖ If
you select it, all packages that come with RedHat Linux will be
installed at about 3.7GB.
• You can select a package by clicking on the checkbox next to it. If you
select ―select individual packages‖ then when you click next, you will
be given a chance to select individual components of these packages.
Firewall Configuration….
• As you can see in figure 10, there is a detailed explanation of each package
available, which can help you decide whether or not you want to install it.
Briefly, Gnome and KDE are two graphical user interface packages. You
can choose either one or both of these to install. It‘s only a matter or
personal preference as to which one you like later on. Some people like one,
some like the other. Given sufficient hard disk space, you are welcome to
try both out. I prefer KDE over Gnome.
• When you are done and click next, the setup program looks for any missing
dependencies for any modules that you selected. If there is any package that
you did not select, and some other package you selected depends on it, you
will be notified of the missing package and asked if you would like to
install the missing packages. We recommend that you select to install the
missing packages.
Firewall Configuration….
• If you had decided to install the X Window System package, then the
next step will be vide configuration for X Window system. If your
video card does not appear on the list (see Figure 11), X may not
support it. However, if you have technical knowledge about your card,
you may choose Unlisted Card and attempt to configure it by
matching your card's video chipset with one of the available X servers.
Figure 10: Individual package selection
Figure 11: Video Card Setup
Firewall Configuration….
• Next, enter the amount of video memory installed on your video card.
If you are not sure, please consult the documentation accompanying
your video card. You will not damage your video card by choosing
more memory than is available, but the X server may not start
correctly if you do. If you decide that the values you have selected are
incorrect, you can click the Restore original values button to return to
the suggested settings. You can also select Skip X Configuration if
you would rather configure X after the installation or not at all.
Firewall Configuration….
• You will next see a screen that will prepare you for installation of
RedHat Linux and the actual package installation will start. At this
point you have to do no intervention and have to wait for the
installation to complete.
• The progress bars will keep you up to date about the current and
overall progress. Once the package installation is complete, the next
screen will offer you to make a boot disk. If you have a spare blank
formatted disk with you, setup can create a boot disk for you which
will be very handy in case of any disastrous situation.
Firewall Configuration….
• However, since you chose to install LILO, this is not necessary. You may
just click on ―skip boot disk creation‖ and continue on to the next
step. If you are installing X Window System and did not select to skip X
Configuration earlier, the next step will be configuration of your monitor.
Most monitors are listed on this screen and you can select the appropriate
monitor from the list.
• If your monitor does not appear on the list, select the most appropriate
Generic model available. By selecting a Generic monitor, Xconfigurator
will suggest horizontal and vertical sync ranges. These values are generally
available in the documentation which accompanies your monitor, or from
your monitor's vendor or manufacturer; please check your documentation to
make sure these values are set correctly.
Figure 12: Custom configuration
Congratulations, installation process has been completed.
Lab Session 02
• OBJECT

Familiarization with some of the most frequently used Linux


commands.
Linux command
• A Linux command is any executable file. That is, a command consists
of any file that is designed to be run, as opposed to files containing
data or configuration information. This means that any executable file
added to the system becomes a new command on the system. Most
Linux commands are very flexible. When you enter a Linux command,
there are several ways to tailor the basic command to your specific
needs. There are two main ways used to modify the effect of a
command:
• Specifying or redirecting a command's input and output
• Using command options
Command options
• You can use command options to fine-tune the actions of a Linux
command. Quite often, a Linux command will do almost—but not
quite—what you want it to do. Instead of making you learn a second
command, Linux lets you modify the basic, or default, actions of the
command by using options.
Other parameters
• Linux commands often use parameters that are not actual command
options. These parameters, such as filenames or directories, are not
preceded by a dash.
Input and output redirection
• Linux allows to "pipe" the output from a command so that it becomes another
command's input. This is done by typing two or more commands separated by the
| character. (This character normally is found on the same key as the \ character.
• You must hold down the Shift key or you will get \ instead of |). The | character
means "Use the output from the previous command as the input for the next
command." Therefore, typing command_1|command_2 does both commands, one
after the other, before giving you the results.
• Another thing you can do in Linux is to send output to a file instead of the screen.
There are many different reasons why you might want to do this. You might want
to save a "snapshot" of a command's output as it was at a certain time, or you
might want to save a command's output for further examination. You might also
want to save the output from a command that takes a very long time to run, and so
on.
• To send output to a file, use the > symbol.
• http://www.webminal.org/terminal/
Executing Linux Command
• From the command prompt simply type the name of the command:
$ command
• Where $ is the prompt character for the Bourne shell.

• Or if the command is not on your path type the complete path and
name of the command such as:
• $ /usr/bin/command.
Linux Command
• Some of the frequently used Linux commands are:
• su
• pwd, cd , and ls
• more and less
• find and grep
• man
su
• Description: Runs a new shell under different user and group IDs. If no user is specified,
the new shell will run as the root user.
• Usually, when you want to temporarily become a different user, you will simply switch to
another virtual terminal, log in as the other user, log out when you're done, and return to
your "home" virtual terminal.
• However, there are times when this is impractical or inconvenient. Perhaps all your virtual
terminals are already busy, or perhaps you're in a situation (such as logged on via a
telephone and modem) in which you don't have virtual terminals available.
• In these cases, you can use the su command. "su" stands for "super user." If you type su
by itself, you will be prompted for the root password. If you successfully enter the root
password, you will see the root # prompt, and you will have all of root's privileges. You
can also become any other user by typing su <username>. If you are root when you type
su <username>, you are not asked for that user's password since in principle you could
change the user's password or examine all the user's files from the root login anyway. If
you are an "ordinary" user trying to change to another ordinary user, you will be asked to
enter the password of the user you are trying to become.
Syntax: su [-flmp] [-c command] [-s shell] [--login]
[--fast] [--preserve-environment] [--
command=command] [--shell=shell] [-] [user]
• (see the man pages for the description of the flags and options)
• $ su <username> (to become another user) or
• $ su (to become the root user).
Adding a new user
• #useradd user1
• #passwd user1
• <password>
pwd
• Description: Displays the name of the current directory.pwd stands
for present working directory. By typing this command you are
informed of which directory you are currently in.
• Syntax: pwd
cd
• Description: Changes the current directory to any accessible directory on
the system.
• Syntax: For instance to change from /home/user1 to a subdirectory of user1
word files use the following:
• $ cd wordfiles
• $ pwd
• /home/user1/wordfiles
• To change to /tmp use the following:
• $ cd /tmp
• $ pwd
• /tmp
ls
• Description: Displays the listing of files and directories. If no file or
directory is specified, then the current directory‘s contents are
displayed. By default the contents are sorted alphabetically.
• Syntax: To view the contents of user1 home directory use this:
• $ ls
• To list the contents of any directory on the system use:
• $ ls /usr
more
• Description: Displays one or more files screen by screen and allows
for searching and jumping to an arbitrary location in the file.

• Syntax: more [-dlfs] [-number] [+number] [file….]


Important flags and options:
-number: sets the number of lines per screen.

+number: specifies the line to start on when displaying.

-d: prompts the user at the end of each screen.

-f: causes long lines not to be folded and to be counted as a single line.

-l: prevents Ctrl+L from being treated as a form feed.

-s: squeezes multiple blank lines into a single blank line.


Important flags and options:….
• For example if there is a large text file called ―textfile‖, it can be
viewed a page at a time with the following command:
• $ more textfile
• After pressing Enter, the first screen of the file is seen with the text -More-
displayed on the last line of the screen. Pressing the space bar jumps
forward a full screen length, while pressing enter key moves forward one
line at a time. When the end of the body of the text is reached, the command
prompt appears. To search forward through a file, enter slash followed by
the word or phrase you want to search for and then press enter. The display
jumps forward to the first occurrence of the word or phrase being searched
for and displays the occurrence near the top of the screen. The same search
can be repeated by entering n after the first search, avoiding the need to type
the same word or phrase repeatedly.
Less
• Description: Displays a text file one screen at a time while allowing searching
and backward scrolling.

• Syntax: less [-aeEGiINrsS] file….. Description: Displays a text file one screen at
a time while allowing searching and backward scrolling.

(the details of the flags can be seen from man pages).
• This command is an improved version of the previous one. On addition to the
functions previously described the following are some of the other actions that can
be performed using less:
• Jumping directly to a line.
• Jumping directly to the beginning or end of file.
• Moving backward through the file.
• Searching backward through the file.
find

• Description: Looks for files below the specified paths that match all
the criteria indicated by the command- line options and takes any
action indicated by those options. If no paths are specified, the search
takes place below the current directory.
find
• Syntax: find [path…..] [options]
• (see the man pages for the flags and options).
• This command can be used to search for files by name, date of creation, size and even file type. To
search for files by name use the following syntax:
• $ find starting-directory parameters actions
• The starting-directory specifies where to begin searching.
• The parameters are where you specify the criteria by which to search. Here use
• –name filename to specify the file to search for.
• The actions section indicates what actions to take on found files. If –print is used then the full name and
path of file is displayed.
• To search for all files named myfile on your system, use this:
• $ find / -name myfile –print
• (Notice that the previous command attempted to search for the entire system. To do this effectively user
must be logged in as the root user).
grep

• Description: Searches files for lines matching a specific pattern and


displays the lines
grep
• grep stands for Global Regular Expression Parser. You will understand
the use of this command right away, but when "Global Regular
Expression Parser" becomes a comfortable phrase in itself, you should
probably consider taking a vacation.
• What grep does, essentially, is find and display lines that contain a
pattern that you specify. There are two basic ways to use grep.
grep
• The first use of grep is to filter the output of other commands. The general syntax
is <command> | grep
• <pattern>. For instance, if we wanted to see every actively running process on the
system, we would type ps -a | grep R. In this application, grep passes on only those
lines that contain the pattern (in this case, the single letter) R. Note that if someone
were running a program called Resting, it would show up even if its status were S
for sleeping, because grep would match the R in Resting. An easy way around this
problem is to type grep " R ", which explicitly tells grep to search for an R with a
space on each side. You must use quotes whenever you search for a pattern that
contains one or more blank spaces.
• The second use of grep is to search for lines that contain a specified pattern in a
specified file. The syntax here is grep <pattern> <filename>. Be careful. It's easy
to specify the filename first and the pattern second by mistake! Again, you should
be as specific as you can with the pattern to be matched, in order to avoid "false"
matches.
grep
• Syntax: Assuming that you are in your home directory, then the following command searches for the word
―hello‖ in each file in your home directory and produces the results as follows:
• $ grep hello*
• This command then returns one line for each occurrence of the word. The name of the file is also shown. In
general the pattern for the grep command is:
• $ grep text-pattern file-list
• The text-pattern can be a simple word or phrase or a more complicated regular expression. The use of
regular expressions can be found in the man pages.
• The file-list can take any form allowed by the shell.
• To check for the contents of all files in a directory use the following:
• $ grep text-pattern *
• where * indicates that all files in the current directory should be searched.
• In its simplest form, the text pattern is a single word or part of a word containing no spaces. To search for a
phrase such as ―is a test‖, enclose the pattern in quotation marks as follows:
• $ grep ―is a test‖ *
USING THE man PAGES
• The man pages are manual pages provided in a standard format with
most Linux software. Almost all the commands that ship with Red Hat
Linux distribution include man pages. Using the man command in its
most basic form, any existing man page can be read:
• $ man command-name
• The above displays the man page for the specified command and
allows scrolling through it and searching it the same way as when
using the less command to display text. If the specified man page
cannot be found an error is displayed.
USING THE man PAGES
• The syntax for the man is as follows: Man [options] [section] [title]
• The man pages are divided into sections:
• Executable programs or shell commands
• System calls (functions provided by the kernel)
• Library calls (functions within system libraries)
• Special files (usually found in /dev)
• File formats and conventions e.g. /etc/passwd
• Games
• Macro packages and conventions
• System administration commands (usually only for a privileged user)
• Kernel routines (nonstandard)
Lab Session 03
• OBJECT
Studying the Linux commands related to files and directories.
Files
The most basic concept of a file defines it as a distinct chunk of
information that is found on the 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, you identify each file by its name and
location. In each location or directory, there can be only one file by a
particular name.
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.
Directories
Linux, like many other computer systems, organizes files in directories.
You 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 you have a directory, A, that contains
another directory, B. Directory B is then a subdirectory of directory A,
and directory A is the parent directory of directory B.
The Root Directory
• In Linux, the directory that holds all the other directories is called the
root directory. This is the ultimate parent directory; every other
directory is some level of subdirectory. 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.
Naming Directories
• Directories are named just like files, and they can contain upper- and lowercase letters, numbers,
and characters such as -, ., and _. 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 you
can't tell, from this example, whether bin is a file or a directory, although you know that usr must
be a directory because
it holds another item—namely, bin. When you see usr/bin/grep, you know that both usr and bin
must be directories, but again, you can't be sure about grep. The ls program shows directories with
a following /— for example, fido/. This notation implies that you 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 your home
directory, you can create, name, move, and delete files and directories
as you see fit. The location of a user's home directory is specified by
Linux and can't be changed by the user. This is both to keep things tidy
and to preserve system security.
Important Directories in the Linux File
System
• Most of the directories that hold Linux system files are "standard."
Other UNIX systems will have identical directories with similar
contents. This section summarizes some of the more important
directories on a Linux system.
/
• This is the root directory. It holds the actual Linux program, as well as
subdirectories. Do not clutter this directory with your 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
This directory holds user-oriented Linux programs.

• /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 you copy to /dev/fd0, you're actually
sending data to the system's floppy disk. Your 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 you do an ls -l, you see
that you 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 you know what you're doing!).
Creating Files
• Linux has many ways to create and delete files. In fact, some of the
ways are so easy to perform that you have to be careful not to
accidentally overwrite or erase files!
• Return to your home directory by typing cd. Make sure you're in your
/home/<user> directory by running pwd. A file can be created 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 you typed this command. When you redirect to a file, Linux
automatically creates the file if it doesn't already exist.
• What if you want to type text into a file, rather than some command's
output? The quick way is to use the command cat.
The cat Command
• The cat command is one of the simplest, yet most useful, commands in
Linux. The cat command basically takes all its input and outputs it. By
default, cat takes its input from the keyboard and outputs it to the
screen. Type cat at the command line:
$ cat
• The cursor moves down to the next line, but nothing else seems to
happen. Now cat is waiting for some input:
Hello
Hello
What
• Everything you type is repeated on-screen as soon as you press Enter!
How do you get out of this? At the start of a line, type ^D (Ctrl-D). (In
other words, hold down the Ctrl key and press D.) If you're not at the
beginning of a line, you have to type ^D twice. ^D is the Linux "end of
file" character. When a program such as cat encounters a ^D, it
assumes that it has finished with the current file, and it goes on to the
next one. In this case, if you type ^D by itself on an empty line, there
is no next file to go on to, and cat exits. So how do you use cat to
create a file? Simple! You redirect the output from cat to the desired
filename:
$ cat > newfile
Hello world
Here's some text
• Type as much as you want. When you are finished, press ^D by itself
on a line; you will be back at the Linux prompt. Now you want to look
at the contents of newfile. You could use the more or less commands,
but instead, let's use cat. Yes, you can use cat to look at files simply by
providing it with a filename:
$ cat > newfile
Hello world
Here's some text
• You can also add to the end of the file by using >>. Whenever you use
>>, whether with cat or any other command, the output is always
appended to the specified file. (Note that the ^D character does not
appear on-screen)
$ cat >> newfile
Some more lines
^D
$ cat newfile
Hello world Here’s
some text Some more lines
• To discover what cat actually stands for, let's first create another file.
$ cat > anotherfile
Different text
^D
$
• Now, try this:
$ cat newfile anotherfile> thirdfile
$ cat thirdfile
Hello world
Here's some text
Some more lines
Different text
• cat stands for concatenate; cat takes all the specified inputs and
regurgitates them in a single lump. This by itself would not be very
interesting, but combine it with the forms of input and output
redirection available in Linux and you have a powerful and useful tool.
Moving and Copying Files
• You often need to move or copy files. The mv command moves files,
and the cp command copies files. The mv command is much more
efficient than the cp command. When you use mv, the file's contents
are not moved at all; rather, Linux makes a note that the file is to be
found elsewhere within the file system's structure of directories.
• When you use cp, you are actually making a second physical copy of
your file and placing it on your disk. This can be slower (although for
small files, you won't notice any difference), and it causes a bit more
wear and tear on your computer. Don't make copies of files when all
you really want to do is move them!
• The syntax for the two commands is similar:
mv <source> <destination>
cp <source> <destination>

• In the Linux environment renaming a file is just a special case of


moving a file. To move a file to /tmp use this:
$ mv fileone /tmp
• To move the file to /tmp and change the name of the file use this:
$ mv fileone /tmp/newfilename
• By using the above a file can be renamed. Simply move a file from its
existing name to a new name in the same directory:
$ mv fileone newfilename
• Because the mv command can accept more than two arguments so
more than one file can be moved. To move all files in the current
directory with the extension .bak, .tmp, .old to /tmp use this:
$ mv *.bak *.tmp *.old /tmp
Here are some more examples:
• $ ls
• anotherfile newdir/ newfile thirdfile
• $ mv anotherfile movedfile
•$ ls
movedfile newdir/ newfile thirdfile
• $ cp thirdfile xyz
• $ ls
• anotherfile newdir/ newfile thirdfile xyz
• You can use cat (or more or less) at any time to verify that anotherfile
became movedfile, and that the contents of file xyz are identical to the
contents of thirdfile.
• The cp command found at /bin/cp is used for copying and provides a
powerful tool for copy operations. The most basic uses for cp
command are to copy a file from one place to another or to make a
duplicate file in the same directory. For instance to copy a file thisfile
in the current directory to a second file to be called thisfile-copy in the
same directory enter the following command:
$ cp thisfile thisfile-copy
• Using ls –1 to look at the directory listing of the files, you would find
two files with identical sizes but different date stamps. The new file
has a date stamp indicating when the copy operation took place:it is a
new, separate file. Changes to thisfile-copy do not affect the original
thisfile file.
• Similarly to make a copy of thisfile in the /tmp directory use the
following command:

$ cp thisfile /tmp
and if you want to copy thisfile to /tmp but give the new file a different
name, enter
$ cp thisfile /tmp/newfilename
• Also to avoid overwriting a file accidentally use the –i flag of the cp
command which forces the system to confirm any file it will overwrite
when copying. Then a prompt like the following appears:
$ cp –i thisfile newfile
cp: overwrite thisfile?
• An alias for the cp command can be created by using the following:
$ alias cp=’cp –i’

• Here an alias has been defined so that when the cp command is issued,
then actually cp –i
• Is issued. In this way the user is always prompted before overwriting a
file while copying. If the user logs in as the super user or root user this
alias is set by default in most Linux distributions. This is especially
important because making a small mistake as the root user can have
drastic consequences for the whole system.
Copying Multiple Files in One Command
• In DOS only one file or file expression can be copied at a time. To
copy three separate files then three commands must be issued. The
Linux cp command makes this a bit easier. The cp command can take
more than two arguments. If more than two arguments are passed to
the command then the last one is treated as the destination and all
preceding files are copied to this destination.
• For example to copy fileone ,filetwo and filethree in the current
directory to /tmp then the following commands can be issued:
$ cp fileone /tmp
$ cp filetwo /tmp
$ cp filethree /tmp

All this can be bundled into one command like this:


$ cp fileone filetwo filethree /tmp

Similarly wildcards can be used to mix and copy a large number of files in one
command. For instance, this command

$ cp *.txt *.doc *.bak /tmp


• copies all files with any one of the three extensions in one command.
• When copying multiple files in this way it is important to remember
that the last argument must be a directory, since it is impossible to
copy two or more files into a single file.
• To copy an entire directory and all its subdirectories the –R flag of the
cp command is used. This command indicates that a directory is to be
recursively copied. For example if a subdirectory called somedir exists
in the current directory and is to be copied to /tmp then the following
command can be used:
$ cp –R somedir /tmp
• There are several other flags used with the cp command. These are:
• -a/--archive: Copies files and directories recursively, maintaining symbolic links as links and
preserving ownership and permissions of the original files. This is same as –dpR.
• -b/--backup: Makes backup copies of the files before the original are overwritten.
• -d/--no-deference: Copies links as links rather than copying the files to which the links point.
• -f/--force: Forces removal of existing destination files that need to be overwritten.
• -i/--interactive: Prompts before overwriting existing destination files.
• -l/--link: Makes hard links instead of copying files. This applies only to files and not to
directories.
• -p/--preserve: Preserves the ownership and permissions of the original files.
• -R/--recursive: Recursively copies directories. That is for every source directory specified,
every file in the directory and all its subdirectories are copied while retaining the matching
directory structure.
Creating a Directory

• To create a new directory, use the mkdir command. The syntax is


mkdir <name>, where <name> is replaced by whatever you want the
directory to be called. This creates a subdirectory with the specified
name in your current directory:
$ ls
anotherfile newfile thirdfile
$ mkdir newdir
$ ls
anotherfile newdir/ newfile thirdfile
• Note: The mkdir command is already familiar to you if you have used
MS-DOS systems. In MS-DOS, you can abbreviate mkdir as md. You
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 you frequently switch between Linux and MS-DOS, you might want
to use mkdir for both systems. However, be warned that you might
start typing other Linux commands in MS-DOS—for example, typing
ls instead of dir!
Moving Directories
• To move a directory, use the mv command. The syntax is mv <directory>
<destination>. In the following example, you would move the newdir
subdirectory found in your current directory to the /tmp directory:
$ mv newdir /tmp
$ cd /tmp
$ ls
/newdir
• The directory newdir is now a subdirectory of /tmp.
• Note: When you move a directory, all its files and subdirectories go with it.
Removing Files and Directories
Now that you know how to create files and directories, it's time to learn
how to undo your handiwork.
Removing Files
To remove (or delete) a file, use the rm command found at /bin/rm. (rm is a
very terse spelling of remove). The syntax is rm <filename>. For instance:
• $ rm myfile
• removes the file myfile from your current directory.
• $ rm /tmp/myfile
• removes the file myfile from the /tmp directory.
• $ rm *
• removes all files from your current directory. (Be careful when using
wildcards!)
• $ rm /tmp/*files
• removes all files ending in ―files‖ from the /tmp directory.
• Note: As soon as a file is removed, it is gone! Always think about
what you're doing before you remove a file. You can use one of the
following techniques to keep out of trouble when using wildcards.
1. Run ls using the same file specification you use with the rm
command. For instance:
• $ ls * files
• myfiles newfiles samefiles
• $ rm * files
• In this case, you thought you wanted to remove all files that matched
*files. To verify that this indeed was the case, you listed all the *files
(wildcards work the same way with all commands). The listing looked
okay, so you went ahead and removed the files.
2. Use the i (interactive) option with rm:
• $ rm -i *files
• rm: remove 'myfiles’? Y
• rm: remove 'newfiles’? N
• rm: remove 'samefiles'? y
• Note: When you use rm -i, the command goes through the list of files
to be deleted one by one, prompting you for the OK to remove the file.
If you type y or Y, rm removes the file. If you type any other character,
rm does not remove it. The only disadvantage of using this interactive
mode is that it can be very tedious when the list of files to be removed
is long.
Removing Directories
• The command normally used to remove (delete) directories is rmdir. The syntax is rmdir
<directory>. Before you can remove a directory, it must be empty (the directory can't hold any files
or subdirectories).Otherwise, you see
• rmdir: <directory>: Directory not empty
• This is as close to a safety feature as you will see in Linux! This one might mystify you (in your
home directory)
• $ ls
• fido/ root/ zippy/
• $ ls zippy
• core kazoo stuff
• $ rm zippy/*
• $ ls zippy
• $ rmdir zippy
• rmdir: zippy: Directory not empty
• The reason for the Directory not empty message is that files starting with. Usually are special
system files and are usually hidden from the user. To list files whose names start with. You have to
use ls -a. To delete these files, use rm .*:
• $ ls -a zippy
• ./ ../ .bashrc .profile
• $ rm zippy/.*
• rm: cannot remove '.' or '..'
• $ ls -a zippy
• ./ ../
• $ rmdir zippy
• $ ls
• fido/ root/
• $
• You will most often come across this situation in a system
administrator role.
• Sometimes you want to remove a directory with many layers of
subdirectories. Emptying and then deleting all the subdirectories one
by one would be very tedious. Linux offers a way to remove a
directory and all the files and subdirectories it contains in one easy
step. This is the r (recursive) option of the rm command. The syntax is
rm -r <directory>. The directory and all its contents are removed.
• Note: You should use rm -r only when you really have to. To
paraphrase an old saying, "It's only a shortcut until you make a
mistake." For instance, if you're logged in as root, the following
command removes all files from your hard disk, and then it's "Hello,
installation procedure" time (do not type the following command!):
• rm -rf /
• Believe it or not, people do this all too often. Don't join the club!
File Permissions and Ownership
• All Linux files and directories have ownership and permissions. You
can change permissions, and sometimes ownership, to provide greater
or lesser access to your files and directories. File permissions also
determine whether a file can be executed as a command.
• If you type ls -l or dir, you see entries that look like this:
• -rw-r—r— 1 fido users 163 Dec 7 14:31 myfile
• 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 and Directory Ownership
• When you create a file, you are that file's owner. Being the file's owner
gives you the privilege of changing the file's permissions or
ownership. Of course, once you change the ownership to another user,
you can't change the ownership or permissions anymore!

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.
The chown command
• Use the chown (change ownership) command to change ownership of a file.
The syntax is chown
• <owner> <filename>. In the following example, you change the ownership
of the file myfile to root:
• $ ls -l myfile
• -rw-r—r— 1 fido users 114 Dec 7 14:31 myfile
• $ chown root myfile
• $ 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,
you must use su or log in as root.
The chgrp command
• 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. You 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. The syntax of this command is as follows:
• chgrp [-Rcfv] [--recursive] [--changes] [--silent] [--quiet] [--verbose]
group filename…
File Permissions
• Linux lets you specify read, write, and execute permissions for each of the
following: the owner, the group, and "others" (everyone else).
• read permission enables you to look at the file. In the case of a directory, it
lets you list the directory's contents using ls.
• write permission enables you to modify (or delete!) the file. In the case of a
directory, you 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.
• For a concrete example, let's look at myfile again:
• -rw-r—r— 1 fido users 163 Dec 7 14:31 myfile
• 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.
The next nine characters are broken into three groups of three, giving
permissions for owner, group, and other. Each triplet gives read, write, and
execute 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.
• Likewise, the permissions for all others are r—: read-only.
• 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:
• 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 you play with the numbers, you 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.
• Note: If you're familiar with the binary system, think of rwx as a
three-digit binary number. If permission is allowed, the corresponding
digit is 1. If permission is denied, the digit is 0. So r-x would be the
binary number 101, which is 4+0+1, or 5. —x would be 001, which is
0+0+1, which is 1, and so on.
• The following combinations are possible:
• 0 or —-: No permissions at all
• 4 or r—: read-only
• 2 or -w-: write-only (rare) 1 or —x: execute
• 6 or rw-: read and write
• 5 or r-x: read and execute
• 3 or -wx: write and execute (rare) 7 or rwx: read, write, and execute
• Anyone who has permission to read a file can then copy that file.
When a file is copied, the copy is owned by the person doing the
copying. He or she can then change ownership and permissions, edit
the file, and so on.
• Removing write permission from a file doesn't prevent the file from
being deleted! It does prevent it from being deleted accidentally, since
Linux asks you whether you want to override the file permissions. You
have to answer y, or the file will not be deleted.
Changing File Permissions
• To change file permissions, use the chmod (change [file] mode)
command. The syntax is chmod <Specification> file.
• There are two ways to write the permission specification. One is by
using the numeric coding system for permissions:
• Suppose that you are in the home directory.
• $ ls -l myfile
• -rw-r—r— 1 fido users 114 Dec 7 14:31 myfile
• $ chmod 345 myfile
• $ ls -l myfile
• —wxr—r-x 1 fido users 114 Dec 7 14:31 myfile
• $ chmod 701 myfile
• $ ls -l myfile
• -rwx——x 1 root users 114 Dec 7 14:31 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."
• You 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, you would type:
$ chmod go+r myfile
Other ways of using the symbolic file permissions are described in the chmod
man page.
Changing Directory Permissions
• You change directory permissions with chmod, exactly the same way
as with files. Remember that if a directory doesn't have execute
permissions, you can't cd to it.
• Note: 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!
The tar Command
• The tar program was originally used to create system backups on tapes
(or tape archives hence ―tar‖). In its current form, it is widely used for
creating archives of files for distribution.
• To create a tar archive use the following:
• $ tar cvf tar-file-name file-list
• This command creates a new archive specified by the file name tar-
file-name (generally tar files have a
• .tar extension) and then store all files from the file list in this archive.
The file list can follow any valid expression. It is important to
remember that this process copies the files into the archive so there is
no danger that the original files will be deleted in the process. The tar
command is immediately followed by a series of options, in this case
cvf. Each of these options is used to control different aspects of the
behavior of tar command:
• c specifies that you are creating an archive, as opposed to viewing an
existing archive.
• v indicates that the command should be run in verbose mode, which
means that each filename will be displayed as it is copied into the
archive.
• f means that you are archiving to a file, as opposed to a tape drive.
• To archive all the .txt files in the current directory into an archive
called text.tar use the following command:
• $ tar cvf text.tar *.txt
• ab.txt
• pop.txt
• The filenames are listed as they are copied into the archive.
• To copy the entire contents of a directory into an archive tar can be
used. The tar command copies all files and subdirectories in a
directory into an archive file if the directory is a part of file list. So if
there is a directory called vnc and its entire contents are to be copied
into a new archive called vnc.tar the following can be used:
$ tar cvf vnc.tar vnc
• To view the contents of an archive, replace the c option with a t. so to
view the list of files in the vnc.tar archive the following command
could be used:
$ tar tvf vnc.tar
• To extract the contents of an archive into the current directory, replace
the c or t with an x:
$ tar xvf vn.tar
The gzip Command
• While tar is useful for archiving files, it does not perform any
compression. Compression in Linux is generally achieved with gzip
command. Unlike Windows ZIP archives, which compress many files
into a single compressed archive, gzip simply compresses individual
files without compressing them into an archive. For instance if there is
a large file called test.pdf that is to be compressed then the following
can be used:
$ gzip test.pdf
• This command compresses the file and adds a .gz extension to the end
of the file name, changing the name to test.pdf.gz.
• Before compression ls –1 showed that the file size was 110,778 bytes.
After compression the size dropped to 83,729 bytes.
• Any valid shell file expression can be used to list more than a file. For
instance:
$ gzip *
• The above compresses all files in the current directory (but not those
in subdirectories).
• Uncompressing gzip Files
• To uncompress a gzip file, the -d option of the gzip command can be
used:
$ gzip –d test.pdf.gz
• This uncompresses the file and removes the .gz extension, returning
the file to its original uncompressed state with the name test.pdf.
• An alternative command, gunzip, eliminates the need to use the –d
option:
$ gunzip test.pdf.gz
• Software Installation
• We shall discuss only two commands:
• RPM (Red Hat Packet Manager)
• To install a software xyz using RPM , the following command is used:
• rpm ivh /home/user/xyz.rpm
• Switches
• i: install v: verbose h: hash mark showing progress
• e: erase q: query f: upgrade only
• U: upgrade (install software if it is not present, otherwise simply upgrades)
• Source tarfile
• We need to go through the following steps:
• tar xzvf
• z: gzip file v: verbose f:file
• Go through Readme
• ./configure (to create a makefile)
• make (to compile)
• su (to become the administrator)
• make install (to complete the actual installation and take binary files and
place them in appropriate places)
EXERCISE
• Explain what the following commands do (with examples) and practice
them:
• Lockfile
• Cksum
• Comm
• Csplit
• Chattr
• Touch
• Cpio
• Sort
• Fuser
• file
EXERCISE
• What does the z option of the tar command do? Explain with
examples.

• Differentiate between cp and cpio command?

You might also like