You are on page 1of 44

INDEX

S.NO DATE CONTENTS PAGE SIGNATURE

1. BASIC LINUX COMMANDS

USER AND SYSTEM


2. INFORMATION

PIPES AND REDIRECTION


3. COMMANDS

4. DIRECTORY COMMANDS

5. FILTER COMMANDS

6. CHECKING ZERO SIZE FILES

7. THE SUM OF DIGITS

8. GREATEST THREE NUMBERS

9. PALINDROME

10 MULTIPLICATION TABLE
EX.NO: 1

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
echo "1.Make directory"

echo "2.Create file"

echo "3.List file"

echo "4.Remove file"

echo "5.Copy file"

echo "6.Display file"

echo "7.Move file"

echo "8.Compare"

echo "9.Word count"

echo "10.Split"

echo "11.diff"

echo "12.Exit"

while ( true )

do

echo "enter your choice:"

read choice

case $choice in

1)echo "enter the directory name:"

read name

mkdir $name ;;

2)echo "Enter the file name:"

read fname
vi $fname ;;

3)echo "List of files"

ls ;;

4) echo "Enter the file name Remove:"

read rname

rm $rname ;;

5)echo "Enter a sourcefile"

read srname

echo "enter a destination file"

read dtname

cp $srname $dtname ;;

6)echo "Displayfile"

read dispname

cat $dispname ;;

7)echo "Move file/rename"

echo "enter the filename to move:"

read mname

echo "enter destination"

read desname

mv $mname $desname ;;

8)echo "Enter a file1:"

echo "Enter a file2:"

read file2
cmp $file1 $file2 ;;

9)echo "Enter file name to count words"

read wcfile

wc $wcfile ;;

10)echo "Enter file name to split:"

read splitname

split -b 20 $splitname new ;;

11)echo "Enter a file1(differ)"

read dif1

echo "Enter a file2(differ)"

read dif2

diff $dif1 $dif2 ;;

12)echo "Exit"

exit ;;

esac

done
OUTPUT:
[masc@localhost akash]$ vi commands.bsh

[masc@localhost akash]$ chmod +x commands.bsh

[masc@localhost akash]$ ./commands.bsh

1.Make directory

2.Create file

3.List file

4.Remove file

5.Copy file

6.Display file

7.Move file

8.Compare

9.Word count

10.Split

11.diff

12.Exit

enter your choice:

enter the directory name:

it

enter your choice:

Enter the file name:


a.txt

enter your choice:

List of files

1 file1.txt new1 newfile2.txt.txt prog5.bsh

45 file2 newaa prg5.bsh prog6.bsh

a.bsh file3 newab priya prog7.bsh

as.bsh g newac priya.bsh prog8.bsh

a.txt gg newad priya.txt prog9.bsh

cba.txt infotech newae prog10.bsh prog.bsh

commands.bsh ingotech newaf prog1.bsh sam.bsh

d it newag prog2.bsh s.bsh

dummyfile.txt mul.bsh newah prog3.bsh temp

file1 multable.bsh newai prog4.bsh untitled folder

enter your choice:

Enter the file name Remove:

a.txt

enter your choice:

Enter a sourcefile

as.bsh

enter a destination file


a.txt

enter your choice:

Displayfile

a.txt

expr 5 + 34

i=5

expr $i + 1

k= expr

enter your choice:

Move file/rename

enter the filename to move:

as.bsh

enter destination

a.txt

enter your choice:

Enter a file1:

dummyfile.txt

Enter a file2:

cba.txt

dummyfile.txt cba.txt differ: byte 1, line 1


enter your choice:

Enter file name to count words

cba.txt

2 4 26 cba.txt

enter your choice:

10

Enter file name to split:

a.txt

enter your choice:

11

Enter a file1(differ)

dummyfile.txt

Enter a file2(differ)

cba.txt

1,3c1,2

< lkmlkm

< fdlkjldf\

< ndf,df,.mf

---

> im akash

> studing b.sc(it)


enter your choice:

12

Exit

[masc@localhost akash]$
EX.NO:2

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
echo "1.Logged User"

echo "2.Current Working Directory"

echo "3.Oprating System Type"

echo "4.number of logged users"

echo "5.Available shells"

echo "6.CPU Information"

echo "7.Memory Information"

echo "8.Exit"

while(true)

do

echo "Enter your choice"

read n

case $n in

1)whoami ;;

2)pwd ;;

3)uname -a ;;

4)who -u ;;

5)echo $SHELL ;;

6)ps -u;;

7)free ;;

8)exit;;

esac

done
OUTPUT:
[masc@localhost ~]$ ./prog2.bsh

1.Logged users

2.Current workship directory

3.Operating system type

4.Number of logged users

5.Available shells

6.CPU information

7.Memory information

8.Exit

./prog2.bsh: line 8: echo8.Exit: command not found

enter your choice

masc

enter your choice

/home/mit

enter your choice

Linux localhost.localdomain 2.6.32-71.el6.i686 #1 SMP Wed Sep 1 01:26:34 EDT


2010 i686 i686 i386 GNU/Linux

enter your choice

4
masc tty1 2000-12-31 19:09 old 1927 (:0)

masc pts/0 2000-12-31 21:19 . 3817 (192.168.10.35)

masc pts/1 2000-12-31 19:21 01:49 2615 (192.168.10.10)

masc pts/2 2000-12-31 21:16 . 3751 (192.168.10.33)

masc pts/3 2000-12-31 21:21 . 3893 (192.168.10.10)

masc pts/4 2000-12-31 21:23 . 3947 (192.168.10.40)

masc pts/5 2000-12-31 21:05 . 3389 (192.168.10.9)

masc pts/6 2000-12-31 20:58 00:06 3205 (192.168.10.34)

masc pts/7 2000-12-31 21:08 00:01 3435 (192.168.10.5)

masc pts/8 2000-12-31 21:12 00:01 3599 (192.168.10.12)

masc pts/9 2000-12-31 21:24 . 4085 (192.168.10.4)

enter your choice

/bin/bash

enter your choice

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
COMMAND

masc 2620 0.0 0.1 5216 1684 pts/1 Ss+ 19:20 0:00 -bash

masc 3213 0.0 0.1 5216 1688 pts/6 Ss+ 20:58 0:00 -bash

masc 3401 0.0 0.1 5216 1676 pts/5 Ss 21:05 0:00 -bash

masc 3441 0.0 0.1 5216 1752 pts/7 Ss 21:08 0:00 -bash
masc 3605 0.0 0.1 5216 1684 pts/8 Ss 21:12 0:00 -bash

masc 3628 0.0 0.3 11048 3220 pts/8 S+ 21:12 0:00 vim commands.bsh

masc 3737 0.0 0.2 10776 2984 pts/5 S+ 21:15 0:00 vim

masc 3756 0.0 0.1 5216 1784 pts/2 Ss+ 21:16 0:00 -bash

masc 3827 0.0 0.1 5216 1688 pts/0 Ss 21:19 0:00 -bash

masc 3900 0.0 0.1 5216 1684 pts/3 Ss 21:21 0:00 -bash

masc 3944 0.0 0.3 10908 3236 pts/7 S+ 21:22 0:00 vim prg13.bsh

masc 3980 0.0 0.1 5216 1680 pts/4 Ss+ 21:23 0:00 -bash

masc 4081 0.0 0.0 5216 876 pts/0 S+ 21:23 0:00 -bash

masc 4082 0.0 0.0 5216 924 pts/3 S+ 21:23 0:00 -bash

masc 4093 0.1 0.1 5216 1680 pts/9 Ss+ 21:24 0:00 -bash

masc 4126 4.0 0.0 4768 1016 pts/3 R+ 21:24 0:00 ps -u

enter your choice

total used free shared buffers cached

Mem: 1025228 403456 621772 0 30904 172532

-/+ buffers/cache: 200020 825208

Swap: 2064376 0 2064376

enter your choice:

exit
EX.NO:3

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
echo "1.pipes"

echo "2.redirection"

echo "3.tee commands"

echo "4.exit"

while(true)

do

echo "enter ur choice:"

read n

case $n in

1)echo "list of files"

ls

echo "After piping operation(the first 3 files)"

ls | head -3;;

2)ls > file2

ls ;;

3)ls | tee file1 file2 file3 ;;

4)exit

esac

done
OUTPUT:
[masc@localhost akash]$ chmod +x prog3.bsh

[masc@localhost akash]$ ./prog3.bsh

1.pipes

2.redirection

3.tee commands

4.exit

enter ur choice:

list of files

1 commands.bsh g multable.bsh newad newai priya.txt


prog4.bsh prog9.bsh untitled folder

45 d gg new1 newae newfile2.txt.txt prog10.bsh prog5.bsh


prog.bsh

a.bsh dummyfile.txt infotech newaa newaf prg5.bsh prog1.bsh


prog6.bsh sam.bsh

as.bsh file1.txt ingotech newab newag priya prog2.bsh


prog7.bsh s.bsh

cba.txt file2 mul.bsh newac newah priya.bsh prog3.bsh


prog8.bsh temp

After piping operation(the first 3 files)

45

a.bsh
enter ur choice:

1 commands.bsh g multable.bsh newad newai priya.txt


prog4.bsh prog9.bsh untitled folder

45 d gg new1 newae newfile2.txt.txt prog10.bsh prog5.bsh


prog.bsh

a.bsh dummyfile.txt infotech newaa newaf prg5.bsh prog1.bsh


prog6.bsh sam.bsh

as.bsh file1.txt ingotech newab newag priya prog2.bsh


prog7.bsh s.bsh

cba.txt file2 mul.bsh newac newah priya.bsh prog3.bsh


prog8.bsh temp

enter ur choice:

45

a.bsh

as.bsh

cba.txt

commands.bsh

dummyfile.txt

file1.txt

file2
g

gg

infotech

ingotech

mul.bsh

multable.bsh

new1

newaa

newab

newac

newad

newae

newaf

newag

newah

newai

newfile2.txt.txt

prg5.bsh

priya

priya.bsh

priya.txt

prog10.bsh

prog1.bsh
prog2.bsh

prog3.bsh
EX.NO:4

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
echo "1.date"

echo "2.who logged on ?"

echo "3.file listing and directories"

echo "4.exit"

while(true)

do

echo "enter ur choice:"

read n

case $n in

1)date;;

2)who;;

3)ls ;;

4)exit;;

esac

done
OUTPUT:
1.date

2.who logged on?

3.file listing and directories

4.exit

enter your chioce:

Sun Dec 31 19:05:32 EST 2000

enter your chioce:

masc pts/0 2000-12-31 19:02 (169.254.247.122)

enter your chioce:

asd file3 pgr1.bsh pgr9.bsh s.txt v.txt.txt

a.txt guna pgr4.bsh program1.bsh s.txt.txt

command.bsh os.bsh pgr5.bsh ps.txt sum.bsh

d.txt.txt palindrome.sh pgr6.bsh siva sumno.bsh

file1 pdf pgr7.bsh siva.txt sum.sh

file2 pgr10.bsh pgr8.bsh statement.bsh temp

enter your chioce:

4
EX.NO:5

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
echo "Filter Command"

echo "1.Grep(matching pattern)"

echo "2.wc filter"

echo "3.cut filer"

echo "4.tr filter"

echo "5.exit"

while(true)

echo "enter ur choice:"

do

read n

case $n in

1)echo "Enterb file name:"

read f

echo "enter search word:"

read s

grep $s $f ;;

2)echo "Enter the file name:"

read f

wc $f ;;

3)echo "Enter the word:"

read word

echo "Enter the no of character to cut:"


read c

echo "$word" | cut -b $c ;;

4)echo "Enter filename to create:"

read name

vi $name.txt

echo "Before Translation---"

cat $name.txt

echo "After Translation---"

cat $name.txt |tr "[a-z]" "[A-Z]" ;;

5)echo "exit"

exit ;;

esac

done
OUTPUT:
[masc@localhost akash]$ chmod +x prog5.bsh

[masc@localhost akash]$ ./prog5.bsh

Filter Command

1.Grep(matching pattern)

2.wc filter

3.cut filer

4.tr filter

5.exit

enter ur choice:

Enter file name:

prog10.bsh

enter search word:

echo

echo "Enter a number"

echo -n " $n X $i = "

enter ur choice:

Enter the file name:

prog10.bsh

10 29 120 prog10.bsh

enter ur choice:
3

Enter the word:

wikipedia

Enter the no of character to cut:

enter ur choice:

Enter filename to create:

newfile2.txt

Before Translation---

hi

this

is my

program

After Translation---

HI

THIS

IS MY

PROGRAM

enter ur choice: 5

exit
EX.NO:6

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
clear

echo "enter the filename:"

read fname

if [ -s $fname ]

then

echo "file size is not zero bytes"

echo " the details of the file are"

ls -l $fname

else

echo "file size is zero bytes"

rm $fname

fi
OUTPUT:
[masc@localhost akash]$ chmod +x prog6.bsh

[masc@localhost akash]$ ./prog6.bsh

enter the filename:

dummyfile.txt

file size is not zero bytes

the details of the file are

-rw-r--r--. 1 masc mit 28 Dec 31 20:10 dummyfile.txt

[masc@localhost akash]$ ./prog6.bsh

enter the filename:

dummy2.txt

file size is zero bytes


EX.NO:7

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
echo -n "Enter the number:"

read n

sd=0

sum=0

while [ $n -gt 0 ]

do

sd=$(( $n % 10 ))

n=$(( $n / 10 ))

sum=$(( $sum + $sd ))

done

echo "The sum of digit is: $sum"


OUTPUT :

[masc@localhost akash]$ chmod + prog7.bsh

[masc@localhost akash]$ ./prog7.bsh

Enter the number:789

The sum of digit is: 24

[masc@localhost akash]$ ./prog7.bsh

Enter the number:222

The sum of digit is: 6

[masc@localhost akash]$
EX.NO:8

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:
echo "enter the first number"

read first

echo "enter the second number"

read sec

echo "enter the third number"

read third

if [ $first -gt $sec ]; then

if [ $first -gt $third ]; then

echo -e "$first is greatest number"

else

echo -e "$third is greatest number"

fi

else

if [ $sec -gt $third ]; then

echo -e "$sec is greatest number"

else

echo -e "$third is greatest number"

fi

fi
OUTPUT:
[masc@localhost akash]$ chmod +x prog8.bsh

[masc@localhost akash]$ ./prog8.bsh

enter the first number

45

enter the second number

100

enter the third number

96

100 is greatest number


EX.NO:9

DATE:

AIM:

ALGORITHM:
PROGRAM CODING:

echo "enter the string:"

read str

echo $str>temp

res="$(rev temp)"

if [ $str == $res ]; then

echo "its a palindrome"

else

echo "its not a palindrome"

fi
OUTPUT:
[masc@localhost akash]$ chmod +x prog9.bsh

[masc@localhost akash]$ ./prog9.bsh

enter the string:

APPA

its a palindrome

[masc@localhost akash]$ ./prog9.bsh

enter the string:

INFOTECH

its not a palindrome

[masc@localhost akash]$
EX.NO:10

DATE:

AIM:

AL;GORITHMl:
PROGRAM CODING:
echo "Enter a number"

read n

i=1

while [ $i -le 10 ]

do

echo -n " $n X $i = "

expr $n \* $i

let "i++"

done
OUTPUT:
masc@localhost akash]$ vi prog10.bsh

[masc@localhost akash]$ chmod +x prog10.bsh

[masc@localhost akash]$ ./prog10.bsh

Enter a number

9X1=9

9 X 2 = 18

9 X 3 = 27

9 X 4 = 36

9 X 5 = 45

9 X 6 = 54

9 X 7 = 63

9 X 8 = 72

9 X 9 = 81

9 X 10 = 90

You might also like