Custom Search

Monday 3 September 2012

Write a linux program in Shell Script to count number of files in a directory


Write a linux program in Shell Script to count number of files in a directory


Program
echo "enter the complete path of your directory"
read n
if [ -z $n ]; then
#print number of files in current directory
ls -l | grep "^-" | wc -l
fi
#first check whether directory exist or not
test -d "$n" && echo -e "number of files in $n is `ls -l $n | grep "^-" | wc -l`\n" || echo -e "not a directory\n"

No comments:

Post a Comment

Laptops