Professional Documents
Culture Documents
LAB MANUAL
FILE RELATED
I. cat:
Syntax: cat file File displays file contents
cat > file Creates new file.
cat>> file Appends to an existing file.
Usage: Display file contents, Creates new file, or appends data to an existing file.
Syntax: mv[-if]file1[file2...]target
Usage: Renames a file, or moves a file or group of files.
Examples:
mv file1 Renames file1,to file2
mv old Moves the old file to the directory “archive”
V. rm:Remove file
Syntax: mv[-f][-i][-r]file
Usage: Removes files(Deletes files)
Options:
i interactive removal
r Recursive removal
f Forceful removal
FILTERS
I. head:
Syntax: head[-n]file
Usage: Display top of the file.
Options:
n:indicates number of lines to be displayed top of a file
Examples:
head test.txt displays first 10 linesoffilestest.txt
Head -20test.txt displays first 20 lines of filestest.txt
II. tail:
Syntax: tail[-n]file
Usage: Display end of the file.
Options:
n:indicates number of lines to be displayed top of a file
Examples:
tail test.txt displays last 10 linesoffilestest.txt
tail -20test.txt displays last 20 linesoffilestest.txt
PACKAGE RELATED
I. apt-get install
Syntax: apt-get install package
Usage:
● apt-get is the command-line tool used for install APT(advanced packaging Tool)software
packages.
● It is rapid ,practical and efficient way to unstall packages on your system.
Examples:
Apt-get install libc Install libc6,which libraries of the embedded GNU
C library.
II. apt-get remove
Syntax: apt-get remove package
Usage:
● apt-get is the command-line tool used for remove APT(advanced packaging Tool)software
packages.
Examples:
apt-get remove libc6 remove/uninstall libc6.
These advanced Unix commands will allow you to accomplish various tasks in Unix and Unix
like operating systems, generally giving you more options for managing your data and getting things
done.
It is best if you get familiar with the basic Unix commands first.Since this is an index of
commands, do take a minute to explore each of the pages for all the listed commands, they contain
examples of advanced usage of seemingly simple commands. There's also a very useful Unix Reference
section that explores some of the most useful topics at greater length and depth.
● basename – get filename from the full path (remove directory names)
● ln – make links and symlinks to files and directories
● find – finding files and directories in Unix
Networking
per=100
subjectTotal=210
echo $percentages
if [ $percentages -gt 80 ]
then
echo "Class A"
else if [ $percentages -gt 70 ]
then
echo "Class B"
else if [ $percentages -gt 60 ]
then
echo "Class C"
fact=1
echo $fact
5.write a shell script which will accept a number b and display first n prime
numbers as output.
prime_1=0
echo "enter the range"
read n
echo " Prime number between 1 to $n is:"
echo "1"
echo "2"
for((i=3;i<=n;))
do
for((j=i-1;j>=2;))
do
if [ `expr $i % $j` -ne 0 ] ; then
prime_1=1
else
prime_1=0
break
fi
j=`expr $j - 1`
done
if [ $prime_1 -eq 1 ] ; then
echo $i
fi
i=`expr $i + 1`
done
6. Write a shell script which accepts number b and generates the first N prime
number.
echo "Enter the number upto which you want prime numbers:"
read n
for ((i=1;i<=n;++))
do
flag=0
for ((j=2;j<i;j++))
do
if [$flag-eq 0]
then
echo $i
fi
done
echo "Enter the number upto which you want prime numbers:"
read n
for ((i=1;i<=n;++))
do
flag=0
for ((j=2;j<i;j++))
do
if [$flag-eq 0]
then
echo $i
fi
done
7. Write a shell script which will generate first n Fibonacci numbers like:
1,1,2,3,5,13
1. Step 1: Start
2. Step 2: Declare variable
3. Step 3: Initialize variable
4. Step 4: Read n from user
5. Step 5: Print x and y
6. Step 6: Repeat until i<n
7. 6.1 x=x+y
8. 6.2 print z
9. 6.3 x=y, y=z
10. 6.4 i=i+1
11. Stop 7: Stop
10. write a shell script to display all executable files, directories and zero sized
files from current directory.
clear
echo "Enter Directory Name:"
read dir
ls $dir>tempfile.txt
count=0
if [ -d $dir ];then
for filename in `cat tempfile.txt`
do
if [ -x $filename ];then
echo "$filename"
count=`expr $count + 1`
fi
done
fi
echo "Total Executable Files Are $count"
rm tempfile.txt
Note that the environment variables are set without using the $ sign but while accessing them we use the
$ sign as prefix. These variables retain their values until we come out of the shell.
When you log in to the system, the shell undergoes a phase called initialization to set up the
environment. This is usually a two-step process that involves the shell reading the following files −
● /etc/profile
● profile
As soon as both of these files have been read, the shell displays a prompt −
$
Environment Variables
Following is the partial list of important environment variables. These variables are set and accessed as
mentioned below −
Contains the identifier for the display that X11 programs should use by default.
2
HOME
Indicates the home directory of the current user: the default argument for the cd built-in
command.
3
IFS
Indicates the Internal Field Separator that is used by the parser for word splitting after
expansion.
4
LANG
LANG expands to the default system locale; LC_ALL can be used to override this. For
example, if its value is pt_BR, then the language is set to (Brazilian) Portuguese and the
locale to Brazil.
5
LD_LIBRARY_PATH
A Unix system with a dynamic linker, contains a colonseparated list of directories that the
dynamic linker should search for shared objects when building a process image after exec,
before searching in any other directories.
6
PATH
Indicates the search path for commands. It is a colon-separated list of directories in which
the shell looks for commands.
7
PWD
8
RANDOM
9
SHLVL
Increments by one each time an instance of bash is started. This variable is useful for
determining whether the built-in exit command ends the current session.
10
TERM
11
TZ
Refers to Time zone. It can take values like GMT, AST, etc.
12
UID
Expands to the numeric user ID of the current user, initialized at the shell startup.
13. Write an awk program using function, which convert each word in a given
text into capital.
// starting
to_upper_case() // create user define function
{
a="the world is so beautiful"
echo "$a" | awk '{print toupper($0)}'
}
#include<stdio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
Modern multiprocessing operating systems allow many processes to be active, where each
process is a “thread” of computation being used to execute a program. One form of multiprocessing is
called time-sharing, which lets many users share computer access by rapidly switching between them.
Time-sharing must guard against interference between users’ programs, and most systems use virtual
memory, in which the memory, or “address space,” used by a program may reside in secondary memory
(such as on a magnetic hard disk drive) when not in immediate use, to be swapped back to occupy the
faster main computer memory on demand. This virtual memory both increases the address space available
to a program and helps to prevent programs from interfering with each other, but it requires careful
control by the operating system and a set of allocation tables to keep track of memory use. Perhaps the
most delicate and critical task for a modern operating system is allocation of the CPU; each process is
allowed to use the CPU for a limited time, which may be a fraction of a second, and then must give up
control and become suspended until its next turn. Switching between processes must itself use the CPU
while protecting all data of the processes.
The first digital computer had no operating systems. They ran one program at a time, which had
command of all system resources, and a human operator would provide any special resources needed. The
first operating systems were developed in the mid-1950s. These were small “supervisor programs” that
provided basic I/O operations (such as controlling punch card readers and printers) and kept accounts of
CPU usage for billing. Supervisor programs also provided multiprogramming capabilities to enable
several programs to run at once. This was particularly important so that these early multimillion-dollar
machines would not be idle during slow I/O operations.
Computers acquired more powerful operating systems in the 1960s with the emergence of time-
sharing, which required a system to manage multiple users sharing CPU time and terminals. Two early
time-sharing systems were CTSS (Compatible Time Sharing System), developed at the Massaachusetts
Institute of Technology, and the Dartmouth College Basic System, developed at Dartmouth College.
Other multiprogrammed systems included Atlas, at the University of Manchester, England, and IBM’s
OS/360, probably the most complex software package of the 1960s. After 1972 the Multics system for
General Electric Co.’s GE 645 computer (and later for Honeywell Inc.’s computers) became the most
sophisticated system, with most of the multiprogramming and time-sharing capabilities that later became
standard.
The minicomputer of the 1970s had limited memory and required smaller operating systems. The
most important operating system of that period was UNIX, developed by AT&T for large minicomputers
as a simpler alternativs to Multics. It became widely used in the 1980s, in part because it was free to
universities and in part because it was designed with a set of tools that were powerful in the hands of
skilled programmers. More recently, Linux, an open-source version of UNIX developed in part by a
group led by Finnish computer science student Linus Torvalds and in part by a group led by American
computer programmer Richard Stallman, has become popular on personal computers as well as on larger
computers.
Linux is most famous free and open source Operating System.Open source operating Systems are
available in source code format rather than as compiled binary code. Free Software means not by money
point of view.But software that is free,like linux,is distributed along with its source code.So that anyone
who receives it is free to make changes and redistribute it.You can make change to the source code of
Linux as per your requirements. Not only this,but you can also distribute this modified OS.You need to
concern that you have to provide your modified source code with this os.
Many people done such type of work,and as a result there are many flavours of Linux available
in the market.Some of the known ones are, Red Hat Enterprise Linux and its derivative such as Fedora
and CentOS,Debian and its derivatives such as Ubuntu and Linux Mint,Linspire,PCLinux Day by
day,Linux is becoming famous.It uses most of the features of UNIX ,it is multi-user,multitasking,
Operating System that also supports a handy Graphical User Interface(GUI).It is quite robust and
secure.You will rarely hear about virus attack on Linux System,as with windows.Linux can be found on a
wide range of devices from personal computer,mobiles,tablets and embedded systems to mainframe and
supercomputers.