0% found this document useful (0 votes)
5 views2 pages

Shell Script to Check Directory Status

The document outlines a shell script that prompts the user for a filename and checks if it is a directory. If it is a directory, the script displays its contents; otherwise, it informs the user that the file is not a directory. Multiple script variations are provided to achieve the same functionality.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Shell Script to Check Directory Status

The document outlines a shell script that prompts the user for a filename and checks if it is a directory. If it is a directory, the script displays its contents; otherwise, it informs the user that the file is not a directory. Multiple script variations are provided to achieve the same functionality.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Script No .

Definition:
Write a shell script that takes a filename from the user and checks whether it is a
directory file or not.
• If it is a directory, then the script should display the contents of the directory.
• If it is not a directory file then script should display the message: “File is not a
directory file “
Script:
#This script accepts a filename and if it directory,
#displays the contents of the directory
clear
echo Enter the filename
read fn
if [ -d $fn ]
then
echo $fn is a directory file
echo Contents of Directory $fn
cd $fn
ls
else
echo File is not a directory file or does not exists
fi

OR
echo "Enter the file name"
read fn
if [ -d $fn ]
then
echo "Its a directory"
ls $fn
else
echo "Its not directory"
fi

OR
if [ -d $1 ]
then
ls
else
echo "File is not a directory file "
fi

You might also like