Showing posts with label count no of file. Show all posts
Showing posts with label count no of file. Show all posts

16 June 2012

Shell Script to Count number of files in a directory

1 comment

Q. How do I count number of files in a directory using Bash Script


Ans:

#!/bin/bash
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"

Output


count no of files in a directory

Enjoy :)

Read More...