What Is Linux?
What Is Linux?
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.
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 :
• Multi-user: several users on the same machine at the same time (and no
two-user licenses!).
1|Page
• Demand loads executables: Linux only reads from disk those parts of a
program that are actually used.
• 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.
• 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:-
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.
Output :- |
• $tput lines :- I t will count the number of lines used by the cursor.
Syntax :- $tput lines
$echo “hello!”
$tput lines
Output:- 2
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
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 :- 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.
Output:-10 October
11. $cal :- It will print the calendar of specific month or a specific year. It can print
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
Example:-$banner hello
13. $passwd :- We cannot create a new password.It helps us to change the old
Example:- $passwd
11 | P a g e
DIRECTORY
COMMANDS OF
LINUX
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 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
Hi!
[ ctrl+z ]
Hello!
[ctrl+z]
$cat s h >w
$cat w
Output:- Hi!Hello!
Hello
[ctrl+z]
$cat >b
13 | P a g e
Everybody
[ctrl+z]
$cat>c
Hi
[ctrl+z]
$cat a>>b>c
$cat c
Example:- $touch n
Example:- $ls
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).
$ chmode g = rw filename
$chmode o = rx filename
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.
Example:- $cat>a
Riya
[ctrl+z]
$cat>b
jain
[ctrl+z]
$c p a b
Hi
[ctrl+z]
$cat>b
Priya
[ctrl+z]
$mv a b
Output:- cat a
Empty file
Cat b
Hi Priya
17.$wc :- This command is used to count character, word and lines present in a
file.
[ctrl+z]
$wc –c
19
$wc –w
16 | P a g e
4
$wc –l
19. $sort :- This command is used to sort the number of lines according to the first
alphabet of the line.
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.
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.
7. Esc k :- This command is used to move to the above line 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.
• Bourne shell
• C shell
• Korn shell
21 | P a g e
1. Shell Program to count number of character, word, lines
$ cat<f1
i am hello
abc
[ctrl+z]
vi f1
cat>f1
wc -c f1
wc -w f1
wc -i
Output
$ sh f1
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
$ mkdir dir1
-...
$ cd dir1
$ vi file1
read age
if [ $ age –ie 18 ]
then
else
then
echo" young"
else
echo" old age"
fi
fi
Output
23
young
24 | P a g e
3.Write a shell program to display date, user, calendar and process
state
date
ps
echo "calender:"
cal
readname
Output
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
gjhhg
your names:
gjhhg
25 | P a g e
4. Write a shell program to search a word in given File
clear
cat>text
read 'word
then
else
fi
Output
hello everyone.
search
hello
hello everyone
26 | P a g e
5. Write shell program to print the multiplication Table
clear
read n
echo "table for $n is :\n"
i=1
do
t='expr $n\*$i'
i='expr $i+1'
done
Output
enter the number whose table is to form 8
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
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
fact=1
n='expr $n-1'
done
Output
factorial is.
120
31 | P a g e
8.Write a shell program to display option based on-
-Is
-date
-who
-Is –l
clear
do
read ch
case $ch in
1) is ;;
2) date ;;
3) who ;;
4) is -i ;;
q) break ;;
esac
done
32 | P a g e
OUTPUT
press q to exit
1 -> Is
2 -> date
3 -> who
4 -> Is –I
33 | P a g e
9.Write a shell program to check whether the no. is less than or
greater than 50
clear
read n
if [ $n -lt 50]
then
else
fi
Output
enter the no
20
76
34 | P a g e
10.Write a shell program to accept number from user and display
read n
then
else
fi
Output
25
35 | P a g e
11.Write a shell program to copy, edit, rename and delete a file
clear
read flname
cat>$flname
echo" 1. copy"
read x
case $x in
read flnm
cp $flname $flnm
$flnm"
echo "$cat$flnm";;
2) vi $flname
read flnm
36 | P a g e
mv $flname $flnm
4)rm $flname
esac
Output
file1
hello everyone
2. edit
3. rename
4. delete
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
read file 1
read file 2
sort –n $fname
echo $fname
38 | P a g e
Output
39 | P a g e
13.Write shell program to check whether the string entered is
palindrome or not
clear
read str
instr=str
count='echo $str/wc-c'
do
done
then
else
fi
40 | P a g e
Output
12321
41 | P a g e
14.Write a Shell Program to see whether the argument is positive
or negative
else
if [$n -gt 0 ]
then
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
read p
result= 1
x~1
while [ $p -ge $x ]
do
(( result = $result \* $n ))
(( p = $ p \ - $x ))
done
echo $result
Output
43 | P a g e
16.Write a Shell Program to display whether a number is
Armstrong or not
read n
x = $n
result=o
while [ $n -ne 0 ]
do
(( rem = $n \% 10 ))
(( n. $n v 10 ))
done
echo $result
if [ $x -eq $result ]
then
else
then
fi
44 | P a g e
45 | P a g e
Output
enter a number
153
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
read f
read s
echo" 1. addition"
echo” 2.subtraction”
echo" 3. multiplication"
echo" 4. division"
read x
case $x in
1) k= 'expr$f+$s'
2) k= 'expr$f-$s'
3) k='expr$f*$s'
4) k= 'expr$f/$s'
47 | P a g e
*) echo "you had entered wrong choice"
esac
read q
done
Output
21
1. addition
2. subtraction
3. multiplication
4. division
9
48 | P a g e
enter the second value or (operand)
1. addition
2. subtraction
3. multiplication
4. division
enter your choice
.--...
2
49 | P a g e
18.Write a shell program to compute area of rectangle and circle.
clear
echo"menu"
read ch
case $ch in
read $in
read $br
area1='expr $in\*$br'
$areal
perimeter='expr 2\*$p'
$perimeter
circle"
read rd
pi = 'expr 22/7'
,
r= 'expr $rd\ *$rd'
50 | P a g e
area2='expr $pi\*$r'
Output
menu
enter option
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"
read name
then
else
fi
Output
abc is logged in
52 | P a g e
20.Write a shell program to form a pascal pyramid
clear
read number
row=4
t1=1
n.:....O
r=0
while[$number -ge 1 ]
do
((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))
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