OSA A4

A4: Creating,deleting directories,changing the working directory and checking the current directory.


->Program:

while true

do

echo "1.Create directory :";

echo "2.Delete directory :";

echo "3.Change the directory";

echo "4.Current Directory:";

echo "5.Exit";

echo "Enter your choice : ";

read ch;

case $ch in

1)

echo "Please enter Directory name : ";

read dir;

if [ -d $dir ]; #check for the directory name entered by the user

then

echo"Directory already existing"

else

mkdir $dir; #create new directory by specified name

echo "Directory created "

ls -t | head -n 15

  fi # end of if statement

;; # to break first switch case

2)

echo "Enter the Directory name to be delete : ";

read dir;

if [ -d $dir ];

then

rmdir $dir;

echo "Directory Deleted successfully";

ls -t | head -n 15 # 'ls -t' displays list of directory by time modified, latest first.

else

echo "No directory by given name";

fi

;;

3)

echo "Changing current working directory to :enter the path: ";

read path

cd $path

pwd

ls -t

;;

4)

echo "Current Working Directory : ";

pwd

;;

5)

exit;

;;

esac # end of switch case

done

OUTPUT:-


[joker415@localhost Documents]$ chmod +x A-4.sh

[joker415@localhost Documents]$ ./A-4.sh

1.Create directory :

2.Delete directory :

3.Change the directory

4.Current Directory:

5.Exit

Enter your choice :

1

Please enter Directory name :

test_dir

Directory created

test_dir

A-4.sh

A-4.sh~

control_serv.c

clean_serv.c

Cleanup

clean_serv.c~

control_serv.c~

Project.docx

All-Sec-A-B-C-OSA-Prog-Assignments

TTT_PPT

quit.c

1.Create directory :

2.Delete directory :

3.Change the directory

4.Current Directory:

5.Exit

Enter your choice :

2

Enter the Directory name to be delete :

test_dir

Directory Deleted successfully

A-4.sh

A-4.sh~

control_serv.c

clean_serv.c

Cleanup

clean_serv.c~

control_serv.c~

Project.docx

All-Sec-A-B-C-OSA-Prog-Assignments

TTT_PPT

quit.c

1.Create directory :

2.Delete directory :

3.Change the directory

4.Current Directory:

5.Exit

Enter your choice :

3

Changing current working directory to : enter the path:

/home/joker415/Downloads

/home/joker415/Downloads

allloggedin.c     allloggedin.c~    a.out    control_serv.c    quit.c

1.Create directory :

2.Delete directory :

3.Change the directory

4.Current Directory:

5.Exit

Enter your choice :

4

Current Working Directory :

/home/joker415/Downloads

1.Create directory :

2.Delete directory :

3.Change the directory

4.Current Directory:

5.Exit

Enter your choice :

5

0 comments:

Post a Comment