I have enhanced the code from the question I posted before:
My code is:
DIR="$1"
if [ -e "$DIR" ]
then
echo -n "total directories:" ; find $DIR -type d | wc -l
echo -n "total files:" ; find $DIR -type f | wc -l
else
if [ -f "$DIR" ]
then
echo " Directory doesn't exist"
else
echo " please pass correct arguments"
fi
fi
This code gives output when I execute ./countfiledirs
or countfiledirs jhfsakl
:
sreekanth@sreekanth-VirtualBox:~$ ./countfiledirs
please pass correct arguments
sreekanth@sreekanth-VirtualBox:~$ ./countfiledirs ffff
please pass correct arguments
I want output when i executed the script name ./countfiledirs
as:
please pass correct arguments
and for ./countfiledirs ffff
as:
directory doesn't exists
I have another problem with the code when I exceuted script ./countfiledirs /usr/share
. It's not giving the actually no of directories and subdirectories for the path which I have given. Instead of 3 directories it's showing 4