INTRODUCTION
What is Linux?
Linux is a UNIX-based operating system originally developed as for Intel-
compatible PC's. It is now available for most types of hardware platforms, ranging
from PDAs (and according to some reports, a wristwatch) to mainframes. Linux is a
"modern operating system", meaning it has such features as virtual memory, memory
protection, and preemptive multitasking.
Linux is built and supported by a large international community of developers and
users dedicated to free, open-source software.
There is a very large collection of free software available for Linux. There are
graphical environments (GUIs), office applications, developers' tools, system utilities,
business applications, document publishing tools, network client and server
applications -- the list goes on.
The best part of this community is that all code is open. This means there is no
barrier to entry; for any given problem, there are generally several applications
that solve the problem.
FEATURES OF LINUX :
• Multitasking: Several programs running at the same time.
• Multi-user: several users on the same machine at the same time (and no
two-user licenses!).
• Multiplatform: Runs on many different CPUs, not just Intel.
• Multiprocessor: SMP support is available on the Intel and SPARC
platforms (with work currently in progress on other platforms), and Linux is used
in several loosely-coupled MP applications, including Beowulf systems
• Multithreading: has native kernel support for multiple independent
threads of control within a single process memory space.
• Has memory protection between processes, so that one program can't
bring the whole system down.
1|Page
• Demand loads executables: Linux only reads from disk those parts of a
program that are actually used.
• Shared copy-on-write pages among executables. This means that
multiple processes can use the same memory to run in. When one tries to write
to that memory, that page (4KB piece of memory) is copied somewhere else.
Copy-on-write has two benefits: increasing speed and decreasing memory use.
• Virtual memory using paging (not swapping whole processes) to disk:
to a separate partition or a file in the file system, or both, with the possibility of
adding more swapping areas during runtime (yes, they're still called swapping
areas). A total of 16 of these 128 MB (2GB in recent kernels) swapping areas can
be used at the same time, for a theoretical total of 2 GB of useable swap space. It
is simple to increase this if necessary, by changing a few lines of source code.
• A unified memory pool for user programs and disk cache, so that all
free memory can be used for caching, and the cache can be reduced when
running large programs.
• Dynamically linked shared libraries (DLL's), and static libraries too, of
course.
• Does core dumps for post-mortem analysis, allowing the use of a
debugger on a program not only while it is running but also after it has crashed.
• Mostly compatible with POSIX, System V, and BSD at the source level.
• All source code is available, including the whole kernel and all drivers,
the development tools and all user programs; also, all of it is freely distributable.
Plenty of commercial programs are being provided for Linux without source, but
everything that has been free, including the entire base operating system, is still
free.
2|Page
LINUX CLIENT SERVER ARCHITECTURE
3|Page
4|Page
COMMAND EXECUTION DIAGRAM
5|Page
6|Page
Linux Architecture:-
Linux Architecture is divided into two parts. These are
(a) Microkernel Architecture.
(b) Monolithic Architecture.
Microkernel Architecture Monolithic Architecture
It is the future architecture It is the past architecture.
It maintains more than one It maintains only one
function at a time. :
function at a time.
More data can be stored. One-by-one usage is
possible.
It uses inter-process No memory management
communication CIPC) & (MM).
memory management.
It uses virtual memory. It uses main memory.
It is complex. It is simple.
The system becomes slow As memory management &
I
due to IPC & memory IPC are not present, hence
management required inside its performance is better.
the micro kernel.
Maintenance is difficult. Maintenance is easy.
It is costly. It is less costly.
7|Page
BASIC COMMANDS
OF
LINUX
1. $echo :- This command is used to display messages. It takes 0,1 or more
number of arguments, which may be given , either in series or in double
quotes.
Syntax : $echo “Message”
Example : $echo “Hello”
8|Page
Output: Hello
2. $tput:- This is used to control the movements of the cursor on the screen.
• $tput clear :- It is used to clear the screen.
• $tput cup r c :- This command is used to place the cursor at rth row and
cth column.
Syntax :- $tput cup row column
Example :- $tput cup 1 20
Output :- |
• $tput lines :- I t will count the number of lines used by the cursor.
Syntax :- $tput lines
Example :- $echo “hi!”
$echo “hello!”
$tput lines
Output:- 2
3. $tty:- In UNIX environment ,every terminal is associated with a special file
called a device file.All the device files are present in a /dev directory. A user can know
the name of his device file on which he/she is working by using tty command.
Syntax:- $tty
Example:- $tty
4. $who:- The user can know the login details of all the current users by using
this command.
5. $who am I:- If we have to see the self login details then we can give
arguments who i.e. am and i.
Syntax :- $who am i
Example :- $who am i
Output :- Administrator ttyn00 Oct 25 11:04
9|Page
6. $uname :- By this command ,we can get the name of the unix system which is
used by the user.
Syntax :- $uname
Example :- $uname
7. $date :- It is used to display the current date along with the time seconds.
Syntax :- $date
Example:- $date
Output :- Thu Oct 23 11:56:05 IST 2008
8. $date + %m :- It will display the name of the month in numeric form.
Syntax:- $date + %m
Example :- $date +%m
Output :- 10
9. $date + %h :-It will display the name of the month in alphabetic form.
Syntax :- $date + %h
Example :- $date + %h
Output :- 10 october
10.$date +%m+ %h :- It will display the name of the month in both numeric as well as
alphabetic form.
Syntax :- $date +%m+ %h
Example :- $date + %m +%h
Output:-10 October
11. $cal :- It will print the calendar of specific month or a specific year. It can print
any calendar for any month or year between 1 and 9999.
Syntax:- $cal
10 | P a g e
Example :- $cal 11 2007
Output:- S M Tu W Th F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
12. $banner :- It will display a banner.
Syntax :- $banner message
Example:-$banner hello
13. $passwd :- We cannot create a new password.It helps us to change the old
password into new one.
Example:- $passwd
Output :- Enter old password: ***
Enter new password: ****
11 | P a g e
DIRECTORY
COMMANDS OF
LINUX
1. $mkdir :- This command is used to make a directory where any number of
files can be stored.
Syntax: $mkdir directory_name
Example :- $mkdir abc
After executing the above command a directory is created with name abc.
12 | P a g e
2. $cd:- This command stands for change directory.This command is used to
change the directory in which you want to work.
Syntax:- $cd directory-name
Example :- $cd abc
3. $cd > filename:- This command is used to create a file.
Syntax:- cd > filename
Example:- cd a
Output:- This command will create a file named a in the directory table.
4. $cat file1 file2 > file3:- This command is used to concatenate two files
and store the contents in third file.
Syntax :- cat file1 file2 >file3
Example:- $cat >s
Hi!
[ ctrl+z ]
Hello!
[ctrl+z]
$cat s h >w
$cat w
Output:- Hi!Hello!
5. $cat file1>>file2>file3:- This command is used to append two files in a
third file.
Syntax: $cat file1>>file2>file3
Example:- $cat >a
Hello
[ctrl+z]
$cat >b
13 | P a g e
Everybody
[ctrl+z]
$cat>c
Hi
[ctrl+z]
$cat a>>b>c
$cat c
Output:- Hi Hello Everybody
6. $rmdir:- This command is used for removing a directory.
Syntax:- $rmdir directoryname
Example:- $rmdir abc
It will remove the directory name abc.
7. $touch:- This command is used to create a empty file.
Syntax:- $touch filename
Example:- $touch n
It will create an empty file named n.
8. $ls :- This command is used for listing the files.
Syntax:- $ls filename
Example:- $ls
Output:- b fibo name switch
country Fibonacci number text
9. $ls –a:- This command is used for listing all files.
10. $ls –x:- This command is used to show the list of row_wise.
14 | P a g e
11.$chmode : This command is used to grant permission for read, write and
execution.
Here permission like read( r),write ( w) and executable ( x) are granted to the
users( u),group (g) or others (o).
syntax:- $ chmode u = rwx filename
$ chmode g = rw filename
$chmode o = rx filename
Example:-$ chmode u= rwx file1
12. $ ps:- This command is used to know the status of the process.
Syntax:- $ ps filename
Example:- $ ps file1
13. $ piping( ):- It is used to filter.It passes the output according to your input.
14. $ cp:- This command is used for copying files.
Syntax:- $c p file1 file2
Example:- $cat>a
Riya
[ctrl+z]
$cat>b
jain
[ctrl+z]
$c p a b
Output:- Riya jain
15. $ mv :- This command is used to move a file
Syntax:- $mv file1 file2
15 | P a g e
Example:- $cat>a
Hi
[ctrl+z]
$cat>b
Priya
[ctrl+z]
$mv a b
Output:- cat a
Empty file
Cat b
Hi Priya
16. $rm:- This command is used to remove a file
Syntax:- file1 $rm* - It will remove all files
File1 $ rm file3 * - It will remove files starting from file3.
17.$wc :- This command is used to count character, word and lines present in a
file.
• $wc –c :- It will count the numbers of characters in the file.
• $wc –w:- It will count the numbers of words in the file.
• $wc –l:- It will count the number of lines in the file.
Example:- $cat >f1
Hello this is linux
[ctrl+z]
$wc –c
19
$wc –w
16 | P a g e
4
$wc –l
18. $cmp:- This command is used to compare two files.
Syntax:- $cmp file1 file2
19. $sort :- This command is used to sort the number of lines according to the first
alphabet of the line.
Syntax:- $sort filename
Example:- cat >st
Parrot
Cat
Goat
Bat
Output:- Bat
Cat
Goat
Parrot
17 | P a g e
EDITOR
COMMANDS
18 | P a g e
1. $Vi :- This command is used to invoke the editor.
Syntax:- $vi filename
Example: $vi f1
2. Esc I :- After invoking the editor, if we want to make any changes in the file then we
can do it by using this command.
3. Esc dd :- This command is used to delete a line from the file while working in a
editor.
4. Esc x :- This command is used to delete a character from the file in the editor.
5. Esc r :- This command is used to modify the character in the file.
6. Esc l :- This command is used to move to the next line.
7. Esc k :- This command is used to move to the above line in the file.
8. Esc o :- This command is used to modify the data in the file.
19 | P a g e
SHELL
PROGRAMMING
20 | P a g e
SHELL:
Some operating system includes the command interpreter in the kernel. Others, like
UNIX, treat the command interpreter as the special program that is running when a job is
initiated or when the user logs on. On systems with multiple commands interpreters to
choose from, the interpreters are known as shell.
In Linux, there are different types of shells are:-
• Bourne shell
• C shell
• Bourne again shell
• Korn shell
What is Shell Script?
The commands written in shell are known as shell script. It is also known as batch file. It is
in ASCII format. Commands related to the operating system are written in it.
21 | P a g e
1. Shell Program to count number of character, word, lines
according to user's file.
$ cat<f1
i am hello
abc
[ctrl+z]
vi f1
echo" enter your file"
cat>f1
echo" number of characters"
wc -c f1
echo" number of words"
wc -w f1
echo" number of lines"
wc -i
Output
$ sh f1
enter your file
f1
number of characters
13
number of words
22 | P a g e
number of lines
23 | P a g e
2. Write a shell program to input the age of a person and
displays that whether a person is a minor, young or old.
$ mkdir dir1
-...
$ cd dir1
$ vi file1
echo" enter the age"
read age
if [ $ age –ie 18 ]
then
echo " minor"
else
if [ $ age -gt 18 -a $ age -ie 25 ]
then
echo" young"
else
echo" old age"
fi
fi
Output
enter the age
23
young
24 | P a g e
3.Write a shell program to display date, user, calendar and process
state
echo ''today's date is:"
date
echo" process state is"
ps
echo "calender:"
cal
echo "what is ur name:"
readname
echo "your name is:" "$name"
Output
today’s date is: nov 16 2009
calender
s m t w t f s
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 28 29
30 31
what s your name:
gjhhg
your names:
gjhhg
25 | P a g e
4. Write a shell program to search a word in given File
clear
echo "this is to search a pattern in your text"
echo "\n enter the text"
cat>text
read 'word
if [gref sword text> /dev/null]
then
echo"\n the word $word is present in line"
gref sword text
else
echo"\n word not found in the text"
fi
Output
this is to search a pattern in your text
enter the text
hello everyone.
enter the word you want to
search
hello
the word hello is present in line
hello everyone
26 | P a g e
5. Write shell program to print the multiplication Table
clear
echo "enter the number whose table is to form"
read n
echo "table for $n is :\n"
i=1
while [$i -lt 11]
do
t='expr $n\*$i'
echo “$n * $i = $t”
i='expr $i+1'
done
Output
enter the number whose table is to form 8
table for 8 is:
8*1=8
8*2=16
8*3=24
8*4=32
8*5=40
8*6=48
8*7=56
8*8=64
8*9=72
8*10=80
27 | P a g e
6. Write a shell program to generate the Fibonacci series
echo "enter the value of n"
read n
a=0
b=1
if [ $n -ge 2 ]
then
echo $a
echo $b
n= $n \- 2
else
if [ $n -eq 1 ]
then
echo $a
n = $n \- 1
fi
fi
while [ $n -ne 0 ]
do
(( c = $a + $b ))
(( echo $c ))
(( a = $b))
,
(( b = $c ))
28 | P a g e
((n = $n\-l))
done
29 | P a g e
Output
enter value of n
7
0
5
8
30 | P a g e
7. Write a shell program to find the factorial of a number
clear
echo “enter the number”
read n
fact=1
while [$n –ge 1]
do
fact=` expr $fact \* $n`
n='expr $n-1'
done
echo ”factorial is :-$fact”
Output
enter the number.
factorial is.
120
31 | P a g e
8.Write a shell program to display option based on-
-Is
-date
-who
-Is –l
clear
while test true
do
echo "enter your choice"
echo “press q to exit”
echo" 1 -> is"
echo "2 -> date"
echo "3 -> who"
echo "4 -> is -i"
read ch
case $ch in
1) is ;;
2) date ;;
3) who ;;
4) is -i ;;
q) break ;;
*) echo this was not in operation
esac
done
32 | P a g e
OUTPUT
enter your choice
press q to exit
1 -> Is
2 -> date
3 -> who
4 -> Is –I
tue nov 16 11:22:15 IST
33 | P a g e
9.Write a shell program to check whether the no. is less than or
greater than 50
clear
echo"enter the no."
read n
if [ $n -lt 50]
then
echo"\n the no. $n is less than 50"
else
echo"\n the no. is greater than 50"
fi
Output
enter the no
20
the number 20 is less than 50 enter the no.
76
the no. 76 is greater than 50
34 | P a g e
10.Write a shell program to accept number from user and display
whether it lies between 1 to 100
echo "enter the number"
read n
if [$n –gt 0 -a$n –le l00]
then
echo "\n the number lies between 1 to 100"
else
echo "\nthe number does not lies between 1 to 100"
fi
Output
enter the number
25
the number lies between 1 to 100
enter the number
120
the number does not lies between 1 to 100
35 | P a g e
11.Write a shell program to copy, edit, rename and delete a file
clear
echo" enter the file name"
read flname
echo "enter the file content"
cat>$flname
echo "list of operations to be performed"
echo" 1. copy"
echo "2. edit"
echo "3. rename"
echo "4. delete"
echo "enter your operation"
read x
case $x in
1) echo "\n enter the filename to which you
want to transfer data"
read flnm
cp $flname $flnm
echo "\n the content of file $flname is copied to file
$flnm"
echo "$cat$flnm";;
2) vi $flname
echo "\n the filename $flname is edited";;
3) echo "\n enter the name with which you want to
rename the file $flname"
read flnm
36 | P a g e
mv $flname $flnm
echo "\n the file $flname renamed with $flnm";;
4)rm $flname
echo "\n the file $flname has been deleted";;
5) echo "\n wrong option"
esac
Output
enter the filename
file1
enter the file content
hello everyone
list of operations to be performed
1. copy
2. edit
3. rename
4. delete
enter your option
enter the name with which you want to rename the file
file2
$cat hello
hello everyone
37 | P a g e
12. Write a shell program to merge the content of 3 files sort and display
the sorted output.
clear
echo “enter the name of first file”
read file 1
echo ”enter the first file contents”
cat > $file1
echo “enter the name of second file”
read file 2
echo ”enter the second file contents”
cat > $file2
echo “enter the name of third file”
cat > $file3
cat $file1$file2$file3 > fname
echo “the merged and sorted output of three files is:”
sort –n $fname
echo $fname
38 | P a g e
Output
enter the name of first file
1
enter the first file contents
hello
enter the second file name
2
enter the second file contents
every
enter the third file name
3
enter the third file contents
one
the merged and sorted output of three file is:
hello
every
one
39 | P a g e
13.Write shell program to check whether the string entered is
palindrome or not
clear
echo "enter the string"
read str
instr=str
count='echo $str/wc-c'
while test $count –gt 0
do
ch='echo $str/cut -c $count'
rev='echo $rev $ch'
done
echo "given string: $str"
,.-... echo "reverse of the string is $rev"
if test $instr -eq $rev
then
echo "the given string is palindrome"
else
echo "the given string is not palindrome"
fi
40 | P a g e
Output
enter the string
12321
given string: 12321
reverse of the string is: - 12321
the given string is palindrome
enter the string
abc
reverse of the string is: - cba
the given string is not a palindrome
41 | P a g e
14.Write a Shell Program to see whether the argument is positive
or negative
echo "enter a number"
read n
if [ $n -ie 0 ]
then
echo "negative number"
else
if [$n -gt 0 ]
then
echo "positive number"
fi
fi
Output
enter a number
positive number
enter a number
-2
negative number
42 | P a g e
15. Write a Shell Program to find the power of a number
echo "enter the number"
read n
echo "enter the power"
read p
result= 1
x~1
while [ $p -ge $x ]
do
(( result = $result \* $n ))
(( p = $ p \ - $x ))
done
echo $result
Output
enter the number
enter the power
43 | P a g e
16.Write a Shell Program to display whether a number is
Armstrong or not
echo "enter a number"
read n
x = $n
result=o
while [ $n -ne 0 ]
do
(( rem = $n \% 10 ))
(( temp = $n \* $rem \* $rem ))
(( result = $result + $temp ))
(( n. $n v 10 ))
done
echo "the armstrong value is"
echo $result
if [ $x -eq $result ]
then
echo "it is an armstrong· no"
else
if[$x –ne $result]
then
echo”it is not an armstrong number”
fi
44 | P a g e
45 | P a g e
Output
enter a number
153
the armstrong value is
153
it is an armstrong number
46 | P a g e
17.Write a shell program to make a calculator
clear
echo "calculator"
q= "y"
while[sq=”y”]
do
echo "enter the first value or operand)"
read f
echo "enter the second value or operand)"
read s
echo" 1. addition"
echo” 2.subtraction”
echo" 3. multiplication"
echo" 4. division"
echo "enter your choice"
read x
case $x in
1) k= 'expr$f+$s'
echo" the sum of two digits is" $k;;
2) k= 'expr$f-$s'
echo" the difference of two digits is" $k;;
3) k='expr$f*$s'
echo "the multiplication of two digits is" $k;;
4) k= 'expr$f/$s'
echo "the division of two digits is" $k;;
47 | P a g e
*) echo "you had entered wrong choice"
esac
echo "want to do another operation (y/n)?"
read q
done
Output
enter the first value or (operand)
21
enter the second value or (operand)
1. addition
2. subtraction
3. multiplication
4. division
enter your choice
the sum of two digit is 26
want to do another operation (y/n)?
enter the first value or (operand)
9
48 | P a g e
enter the second value or (operand)
1. addition
2. subtraction
3. multiplication
4. division
enter your choice
.--...
2
the difference of two digits is 26
want to do another operation (y/n)? n
49 | P a g e
18.Write a shell program to compute area of rectangle and circle.
clear
echo"menu"
echo"1. find the area and perimeter of rectangle"
echo"2. find the area and circumference of circle"
echo"enter the option"
read ch
case $ch in
1) case"enter the length of rectangle"
read $in
case"enter the breadth of rectangle"
read $br
area1='expr $in\*$br'
echo''the area of rectangle is:"
$areal
p='expr $in+ $br'
perimeter='expr 2\*$p'
echo''the perimeter of rectangle is:"
$perimeter
2) echo"enter the radius of
circle"
read rd
pi = 'expr 22/7'
,
r= 'expr $rd\ *$rd'
50 | P a g e
area2='expr $pi\*$r'
echo''the area of circle is " $area2
Output
menu
2. find the area & perimeter of rectangle
3. find the area & circumference of circle
enter option
Enter length of rectangle
Enter breadth of rectangle
The area of rectangle is: 72
The perimeter of rectangle is : 34
51 | P a g e
19.Write a shell program to check whether user is logged or not
clear
echo "to find user is logged in or not"
echo "enter the user"
read name
if who / gref $name
then
echo "$name is logged in"
else
echo "$name is not logged in"
fi
Output
to find user logged in or not
enter the user
abc
administrator abc. Nov 16 11:12
abc is logged in
52 | P a g e
20.Write a shell program to form a pascal pyramid
clear
echo "pascal pyramid"
echo "enter the no. of rows"
read number
row=4
t1=1
n.:....O
r=0
while[$number -ge 1 ]
do
tput cup $row $number
((n1=n))
. ((t=t1))
while[ $t -gt 0 ]
do
((r1=$r))
((n1=$n))
((b=$n1 - $r1))
((f1 - 1))
while[$n 1 - ge 2]
do
(( fl=$f1 \$n1))
((n1=$n1 - 1))
done
53 | P a g e
((f2= 1))
while [ $r1 -ge2] .
do
((f2=$f2\*$r1) )
((r1=$r1 - 1))
done
((f3= = 1))
while [ $b -ge 2 ]
do
( (f3 = $ f3 \ * $ b) )
((b=$b - 1))
done
((term1=$f2 \ $term1))
echo "$term\c"
((t=$t - 1))
((r=$r - 1))
done
((t1=$t1 + 1))
((r=0) )
((n=$n + 1))
((no=$ no - 1))
((row=$row + 1))
done
54 | P a g e
Output
pascal pyramid
enter the no. of rows 4
1
1 1
1 2 1
1 3 3 1
55 | P a g e