Shell script to input a directory name and display the number of files and
sub directories present in the given directory.
Program
echo -n "Enter directory name: "
read dr
dircnt=`ls -l $dr|grep "^d"|wc -l`
filecnt=`ls -l $dr|grep "^-"|wc -l`
echo "No of directories = $dircnt"
echo "No of files = $filecnt"
OUTPUT
Safi $ sh dircnt.sh
Enter directory name: .
No of directories = 10
No of files = 98
Safi $ sh dircnt.sh
Enter directory name: sasha
No of directories = 0
No of files = 4
sub directories present in the given directory.
Program
echo -n "Enter directory name: "
read dr
dircnt=`ls -l $dr|grep "^d"|wc -l`
filecnt=`ls -l $dr|grep "^-"|wc -l`
echo "No of directories = $dircnt"
echo "No of files = $filecnt"
OUTPUT
Safi $ sh dircnt.sh
Enter directory name: .
No of directories = 10
No of files = 98
Safi $ sh dircnt.sh
Enter directory name: sasha
No of directories = 0
No of files = 4
Thanks for the valuable information and insights you have so provided here... word counter tool
ReplyDelete