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
Enjoy :)
If You Liked This Post Please Take a Time To Share This Post
0 comments:
Post a Comment