Sei sulla pagina 1di 5

Homework Title / No.

: - 2

Course Code :- CSE 207

Course Instructor: Ms. Maneet kaur

Student’s Roll No. RC1912A26

Section No. :- C1912

Declaration:
I declare that this assignment is my individual work. I have not copied from
any other student’s work or from any other source except where due
acknowledgment is made explicitly in the text, nor has any part been written
for me by another person.
Student’s Signature
Yogendra Singh
Evaluator’s comments:
______________________________________________________________
_______
Marks obtained : ___________ out of ______________________

1. Linux scripts do not need support comparison symbols


like (<,>, etc.) What is the alternative to do this?

Ans: linux script does not support comparison between greater that(>) or lesser
than(<) are used to redirect output of a command or action somewhere else Or Instead
of < or > Linux scripts have “-lt” for < and “-gt” for > .

For example:
echo enter two nos
read x y
if [ $x –gt $y ]
then
echo x is greater
else
echo y is greater.
fi

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

1. Write a shell script to copy only ordinary files of a


directory to another directory. If it encounters other than
ordinary files, it should give appropriate message. It
should also copy the files to its subdirectories. Illustrate
the use of /boot and /tmp directory
Ans:
echo enter the ordinary file
read filename
if[-f $filename]
then
cp –a /home/user/ $filename
else
echo file is not an ordinary file
fi

/boot: this is a directory that contains the boot loader files like Grub.
Grub is dynamically configurable and it is load at the time of startup.
GRUB provides a simple, command line interface which lets users write new boot
sequences. GRUB is highly portable. It supports multiple executable formats, and is
geometry translation independent.
/temp: a temporary file system which hold temporary files which are cleared at system
reboot.

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2. Write a shell script having the same name as your roll no.
It should input the source and destination directory
names and copy only the files from source to destination.
If it encounters subdirectory, it should not copy and
provide appropriate message for the same.
Ans:
vi rc1912a19
echo enter the source directory name
read sdn
echo enter the destination directory name
read ddn
if [ -f $sdn && -f $ddn]
then
echo the file $sdn and $ddn exist and it is not a directory you cannot copy these files.
else
cp –r $sdn $ddn
echo the files exist and they are copied
fi

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

3. Write a program to list the contents of a directory and its


subdirectories.
Ans:
[user@localhost $] mkdir yogi //it will create a directory yogi//
[user@localhost $]cd yogi
[user@local host yogi] mkdir yogi1 //now yogi1 subdirectory will create of yogi
directory//
[user@local host yogi] mkdir yogi2 //one more subdirectory will create in yogi
directory//
[user@localhost tt]cat>LPU // a file named LPU will create inside yogi2
subdirectory//
Lovely professional university //contents of file LPU//
Save using ctrl+z

Echo enter the directory name


Read n
If [ -d $n ]
Then
Cd $n
Tree
Else
Echo entered name is not found as a directory
Fi

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

5.Write a shell script to perform the following operations for


the directory inputted by user at run time. The menu options
are:
Ans:
echo enter the directory name
read directory_name
cd $directory_name

echo 1. display the contents


echo 2. copy to backup
echo 3. delete files starting with junk
echo 4. exit
read n
case $n in

1) // (a) to display the contents of directory//


ls –l ;;

2) // (b) Copy the files of the directory in the backup


directory//
cp * ../backup;;

3) //(c) Delete the files with the name starting as junk from
the directory//
delete junk*;;

4 ) // (d) to exit //
exit(0);;

*)
break;;

esac

Potrebbero piacerti anche