Escolar Documentos
Profissional Documentos
Cultura Documentos
Semester: 4th
LAB MANUAL
Department: Computer Science and Engineering
Semester: 4th
Syllabus
3. Commands for files & directories: cd, ls, cp, md, rm, mkdir, rmdir.
Creating and viewing files using cat. File comparisons. Disk related
commands: checking disk free spaces. Processes in linux, connecting
processes with pipes, background processing, managing multiple
processes. Manual help. Background process: changing process
priority, scheduling of processes at command, batch commands, kill,
ps, who, sleep. Printing commands, grep, fgrep, find, sort, cal, banner,
touch, file. File related commands ws, sat, cut, grep.
7. Shell Programming
Real-time
A real-time operating system is a multitasking operating system that aims at
executing real-time applications. Real-time operating systems often use
specialized scheduling algorithms so that they can achieve a deterministic
nature of behavior. The main objective of real-time operating systems is their
quick and predictable response to events. They have an event-driven or time-
sharing design and often aspects of both. An event-driven system switches
between tasks based on their priorities or external events while time-sharing
operating systems switch tasks based on clock interrupts.
Multi-user
A multi-user operating system allows multiple users to access a computer
system at the same time. Time-sharing systems and Internet servers can be
classified as multi-user systems as they enable multiple-user access to a
computer through the sharing of time. Single-user operating systems have
only one user but may allow multiple programs to run at the same time.
Multi-tasking vs. single-tasking
A multi-tasking operating system allows more than one program to be running at the
same time, from the point of view of human time scales. A single-tasking system
has only one running program. Multi-tasking can be of two types: pre-emptive and
co-operative. In pre-emptive multitasking, the operating system slices the CPU time
and dedicates one slot to each of the programs. Unix-like operating systems such as
Solaris and Linux support pre-emptive multitasking, as does AmigaOS. Cooperative
multitasking is achieved by relying on each process to give time to the other
processes in a defined manner. 16-bit versions of Microsoft Windows used
cooperative multi-tasking. 32-bit versions of both Windows NT and Win9x, used
pre-emptive multi-tasking. Mac OS prior to OS X used to support cooperative
multitasking.
Distributed
A distributed operating system manages a group of independent computers and
makes them appear to be a single computer. The development of networked
computers that could be linked and communicate with each other gave rise to
distributed computing. Distributed computations are carried out on more than one
machine. When computers in a group work in cooperation, they make a distributed
system.
Embedded
Embedded operating systems are designed to be used in embedded computer
systems. They are designed to operate on small machines like PDAs with less
autonomy. They are able to operate with a limited number of resources. They are
very compact and extremely efficient by design. Windows CE and Minix 3 are some
examples of embedded operating systems.
Memory Management
The activities of memory management handled by OS are—
(1) allocate memory,
(2 ) free memory,
(3) re-allocate memory to a program when a used block is freed, and
(4) keep track of memory usage.
Device Management
The device management tasks handled by OS are
(1) open, close and write device drivers, and
(2) communicate, control and monitor the device driver.
Others can select ‗Skip entering installation number‘ and press ‗OK‘ to proceed.
RHEL would show a warning message, press ‗Skip‘ in it to continue.
Step 6- The Red Hat installer would then require you to create partitions in your
computer‘s hard disk for the installation. You can do it in four ways but the simplest
way is to select ‗Use free space on selected drives and create default layout‘ as this
option will not affect any other OS residing in your system.
Check the ‗review and modify portioning layout‘ to create partitions and click next.
Step 7- In this step you must create the required system partitions and mount points
such as ‗/boot‘, ‗/home‘, ‗swap‘ etc which are required for the Linux‘s proper
functioning.
To create different partitions such as /home, /var etc, click on ‗New‘ to create the
partitions.
Then, select /home in the mount point and choose ‗ext3‘ as the file system and give
the desired size for it and then click ‗OK‘. Similarly also create /boot and /var.
Also, create a swap partition by clicking on ‗New‘ and then choosing the filesystem
as ‗swap‘ and also give the size of Swap partition.(Usually size of swap partition
SHOULD BE twice the size of RAM available to the system but you can keep its
size less than that too)
Once you have made all the desired partitions and given their mount points,
click ‗Next‘ to continue installation.
Step 8- This step pertains to the default OS that will be loaded by the
GRUB loader
(Note- If you have multiple Operating Systems installed, you would see multiple
options here and you have to check in front of the OS name that you want to be
loaded by default when the system is started.)
Click ‗Next‘ to continue.
Step 9- This step pertains to the network settings of the Linux system that you are
going to install. You can select the Ethernet devices through which the system would
communicate with other devices in the network.
You can also provide the hostname, Gateway address and DNS address to the system
during this step. (However it‘s better to adjust these settings once the system has
been fully installed).
Step 10- The next step is to adjust the system clock to your particular time zone.
Select your time zone and then click ‗Next‘.
Step 11 – This is a very important step that deals with the root(super-user)
password for the system . Type the password and confirm it and then click next.
Step 12 – The RHEL installer would then prompt you about if you wish to install
some extra ‗Software Development‘ or ‗Web Server‘ features. By default, keep
it at ‗Customize later‘ and press ‗Next‘.
Step 13- This next step will initiate the installation of Red Hat Linux, press
‗Next‘ to begin the process.
Step 14- Upon the completion of installation you should the following screen.
Press Reboot and you‘d be ready to use your newly installed Red Hat Linux OS.
Experiment 3
Syntax:
CD [/D] [drive:][path]
Cls is a command that allows a user to clear the complete contents of the
screen and leave only a prompt.
Syntax:
CLS
Copy Command Allows the user to copy one or more files to an
alternate location.
Syntax:
COPY [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination]
[/A | /B]] [/V] [/Y | /-Y]
The date command can be used to look at the current date of the computer
as well as change the date to an alternate date.
Syntax:
DATE [date]
The dir command allows you to see the available files and directories in the current
directory. In addition to listing the contents of a directory, the dir command will also
show the last modification date and time, as well as the file size.
Purpose
Basic file operation on a text file such as displaying or creating new files.
Syntax
The basic syntax is as follows:
cat filename
OR
cat > filename
OR
cat [options] filename
OR
cat file1
cat > file2
cat file3 | command
cat file4 | grep something
Display A File
cat filename
cat /path/to/file
cat /etc/passwd
Experiment 4ent 5
AIM : Disk related Commands: Checking disk free
spaces
Checking Disk capacity, Partition tables, etc.
[root@server ~]# fdisk -l
Get Detailed/current information directly from
hard drive [root@server ~]# hdparm -I /dev/sda
Check available/used/free spaces in each
partitions [root@server ~]# df -h
Check Hard drive speeds
[root@server ~]# hdparm -Tt /dev/sda
To list the partition tables for the specified
devices #fdisk -l
Pass print option to displays the
partition table #parted /dev/sda print
To display all disks and storage controllers in the
system #lshw -class disk -class storage
Find Out Disks Name Only
#lshw -short -C disk
Partition the new disk using fdisk command
#fdisk -l | grep '^Disk'
Format the new disk using mkfs.ext3
command #mkfs.ext3 /dev/sdb1
Mount the new disk using mount command
#mkdir /disk1
#mount /dev/sdb1 /disk1
#df -H
Label the partition
#e2label /dev/sdb1 /backup
Checking the Hard Disk for errors
#fsck.file_system_type, E.g #fsck.ext3
Show list of partitions mounted
# df -h [man]
Experiment 56
Process in Linux:
A process is an instance of a program in execution. A process is composed of
several user threads (or simply threads), each of which represents an execution
flow of the process.
However each lightweight process has an independent execution context and
is treated as an independent process by the Kernel. For a deeper understanding
lets take a look at the way a new process is created in Linux. One can use
either the fork() or the clone() command to create a new process. A fork()
always creates a completely independent process which does not share the
address space of the parent process (though a forked process does start with a
pointer to the same address space and a copy-on-write model is used to
optimize space utilization). A clone() on the other hand allows granular
control over process creation and one can specify whether the child process
should share the address space, open files, signals etc with the parent. A
process created using clone() which shares these attributes with its parents is
known as a light-weight process. In effect therefore in Linux everything is a
process which either shares the resources of its parent OR does not. In fact
fork() is implemented as a wrapper over clone() by setting all flags to share
nothing between the parent and child processes.
The p in the leftmost column indicates that fifo1 is a pipe. The rest of the permission
bits control who can read or write to the pipe just like a regular file. On systems with
a modern ls, the | character at the end of the file name is another clue, and on Linux
systems with the color option enabled, fifo| is printed in red by default.
kill 485
Syntax
sleep NUMBER[SUFFIX]...
grep command:
grep is used to search text for patterns specified by the user. It is one of the most
useful and powerful commands on Linux and other Unix-like operating systems.
grep can search any number of files simultaneously. Thus, for example, the
following would search the three files file1, file2 and file3 for any line that contains
the string (i.e., sequence of characters) Lin:
fgrep Command
Purpose
Syntax
Description
The fgrep command searches the input files specified by the File Parameter
(standard input by default) for lines matching a pattern. The fgrep command
searches specifically for Pattern parameters that are fixed strings. The fgrep
command displays the file containing the matched line if you specify more than one
file in the File parameter.
Find Command
The find command is used to locate files on a Unix or Linux system. find will search
any set of directories you specify for files that match the supplied search criteria.
You can search for files by name, owner, group, type, permissions, date, and other
criteria. The search is recursive in that it will search all subdirectories too.
The syntax looks like this:
find where-to-look criteria what-to-do
All arguments to find are optional, and there are defaults for all parts. (This may
depend on which version of find is used. Here we discuss the freely available Gnu
version of find, which is the version available on YborStudent.) For example, where-
to-look defaults to . (that is, the current working directory), criteria defaults to none
(that is, select all files), and what-to-do (known as the find action) defaults to -print
(that is, display the names of found files to standard output). Technically, the criteria
and actions are all known as find primaries.
For example:
find
will display the pathnames of all files in the current directory and all subdirectories.
The commands
find . -print
find -print
find .
Sort command
Sort command is helpful to sort/order lines in text files. You can sort the data in
text file and display the output on the screen, or redirect it to a file. Based on
your requirement, sort provides several command line options for sorting data in
a text file.
Sort Command Syntax:
$ sort [-options]
For example, here is a test file:
$ cat test
zzz
sss
qqq
aaa
BBB
ddd
AAA
Touch command:
The touch command is the easiest way to create new, empty files. It is also
used to change the timestamps (i.e., dates and times of the most recent access
and modification) on existing files and directories.
touch's syntax is
When used without any options, touch creates new files for any file names
that are provided as arguments (i.e., input data) if files with such names do not
already exist. Touch can create any number of files simultaneously.
Thus, for example, the following command would create three new, empty
files named file1, file2 and file3:
touch file1 file2 file3
File command: the file command attempts to classify each filesystem object
(i.e., file, directory or link) that is provided to it as an argument (i.e., input).
BASH ( Bourne- Brian Fox and Free Software Most common shell
Again SHell ) Chet Ramey Foundation in Linux. It's
Freeware shell.
CSH (C SHell) Bill Joy University of The C shell's syntax
California (For and usage are very
BSD) similar to
the C programming
language.
KSH (Korn SHell) David Korn AT & T Bell Labs --
TCSH
Syntax:
if condition
then
if condition
then
.....
..
do this
else
....
..
do this
fi
else
...
.....
do this
fi
Loop defined as:
"Computer can repeat particular instruction again and again, until particular
condition satisfies. A group of instruction that is executed repeatedly is called
a loop."
Bash supports:
for loop
while loop
for loop:
Syntax:
for { variable name } in { list }
do
execute one for each item in the list until the list is
not finished (And repeat all statement between do and done)
done
while loop
Syntax:
while [ condition ]
do
command1
command2
command3
..
....
done
Syntax:
case $variable-name in
pattern1) command
...
..
command;;
pattern2) command
...
..
command;;
patternN) command
...
..
command;;
*) command
...
..
command;;
esac
Experiment 89
'at' is a program to carry out commands that you intend to do only once. It's
mostly used for scheduling specific jobs under specific circumstances. If
you had to rotate your company's webserver logs every Saturday, 'at' is not
the appropriate tool for the job. That would be done best with 'cron', about
which we will talk about shortly. Let say your boss, the CTO, called for a
meeting with you at 1:00. He wants to know how frequently your external
consultants are logging into the network. This is a prime candidate for 'at'.
Use of 'cron'
From a system administrator's point of view, the cron daemon is probably
the best thing since sliced bread. You can schedule practically any program
(provided that they don't have a graphic user interface since cron is not
really designed to run GUI applications) at any time, for any date and at any
interval. That is to say, if you want a text dump of the number of times a
person with the IP address 64.09.200.12 has logged into your computer and
you only want it on February 4th, cron will do this for you.
The jobs that you want to run with cron can be scheduled in various ways.
The most common way is to edit a file which is known as your crontab.
Normally, each user has his/her own and is able to schedule jobs by editing
it. You can add to and delete entries from you crontab by typing:
Code:
crontab –e
Table 1. Guide to Cron times
Variations on a theme
Crontab entries don't have to necessarily have just numbers in them. We can
combine the numbers with other characters to modify how commands get carried
out. For example, I have a USB webcam that doesn't really do what it's supposed
to, which is to take a picture every minute and then shut off. It takes the picture
all right, but it doesn't shut off. So I wrote a script to shut it off and then I added a
crontab entry to call this script every minute. This is what I added:
Code:
0-59/1 * * * * $HOME/shutoff_cam >/dev/null 2>&1
Let's look at this one part at a time
0-59/1
basically means that between the 0-59 minutes of every hour, at every 1 minute
interval, the camera is to shut off. To show you how useful cron is, I remember
seeing a James Bond movie where the perpetual bad-guy, Blofeld, was
brainwashing girls to carry out biological attacks from a base in the Swiss Alps. He
would play these hypnotic tapes to the girls every evening. There is one scene
where you see Blofeld and one of his minions switching the tapes manually. If
only they had had a Linux computer! They could have done this:
Experiment 10
AIM : Write a shell script to find the largest among
the 3 given numbers
Experiment 12
AIM : Introduction to UNIX
UNIX
UNIX is an operating system which was first developed in the 1960s, and has
been under constant development ever since. By operating system, we mean
the suite of programs which make the computer work. It is a stable, multi-
user, multi-tasking system for servers, desktops and laptops.
UNIX systems also have a graphical user interface (GUI) similar to Microsoft
Windows which provides an easy to use environment. However, knowledge
of UNIX is required for operations which aren't covered by a graphical
program, or for when there is no windows interface available, for example, in
a telnet session.
Types of UNIX
There are many different versions of UNIX, although they share common
similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux,
and MacOS X.
Here in the School, we use Solaris on our servers and workstations, and
Fedora Linux on the servers and desktop PCs.
The shell acts as an interface between the user and the kernel. When a user logs in,
the login program checks the username and password, and then starts another
program called the shell. The shell is a command line interpreter (CLI). It interprets
the commands the user types in and arranges for them to be carried out. The
commands are themselves programs: when they terminate, the shell gives the user
another prompt (% on our systems).
The adept user can customise his/her own shell, and users can use different shells on
the same machine. Staff and students in the school have the tcsh shell by default.
The tcsh shell has certain features to help the user inputting commands.
Filename Completion - By typing part of the name of a command, filename or
directory and pressing the [Tab] key, the tcsh shell will complete the rest of the name
automatically. If the shell finds more than one name beginning with those letters you
have typed, it will beep, prompting you to type a few more letters before pressing
the tab key again.
History - The shell keeps a list of the commands you have typed in. If you need to
repeat a command, use the cursor keys to scroll up and down the list or type history
for a list of previous commands.
In the diagram above, we see that the home directory of the undergraduate student
"ee51vn" contains two sub-directories (docs and pics) and a file called report.doc.