0% found this document useful (0 votes)
14 views3 pages

Script 11

The document provides a shell script to count the number of ordinary files and directories in the current directory. It includes multiple variations of the script using different methods to achieve the same result. The output displays the total count of files and directories separately.

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)
14 views3 pages

Script 11

The document provides a shell script to count the number of ordinary files and directories in the current directory. It includes multiple variations of the script using different methods to achieve the same result. The output displays the total count of files and directories separately.

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
You are on page 1/ 3

Script No .

Definition:
Write a shell script to find number of ordinary files and directory files.
Script:
#This script counts the number of files and diretories.
clear
i=` ls -all |wc -l`
echo Total Files in current directory: $i
f=0
d=0
for i in `ls`
do
#echo $i
if [ -d $i ]
then
d=`expr $d + 1`
else
f=`expr $f + 1`
fi
done
echo Number of files $f
echo Number of Directory $d

OR
countd=0
countf=0
for i in *
do
if [ -d $i ]
then
countd=$((countd + 1))
fi
if [ -f $i ]
then
countf=$((countf + 1))
fi
done
echo "Number of directories are $countd"
echo "Number of Ordinary files are $countf"

OR
f=0
d=0
for i in `ls`
do
if [ -f $i ]
then
f=`expr $f +1`
fi
if [ -d $i ]
d=`expr $d +1`
fi
done
echo "Ordinary file : - $f"
echo "Directory : - $d"

You might also like