Loading
View RSS Feed

sachdev

Shell Script To Check Your Home Directory To display Files, Directories, and Sub-Directories Count

Rating: 2 votes, 5.00 average.
Code:
d=0
f=0
for l in `ls -l | tr " " "="`
do
a=`echo $l | cut -c1`
if [ $a = "d" ]
then
((d=$d+1))
elif [ $a = "-" ]
then
((f=$f+1))
fi
done

echo "No. of Dirs=$d"
echo "No. of Files=$f"
output

Code:
[cs08130001045@FileServer ~]$ sh nfile
No. of Dirs=1
No. of Files=9

[cs08130001045@FileServer ~]$ ls -l

-rw-r--r--=1=cs08130001045=cs2008==405=2010-10-30=13:18=]
-rwxr-xr-x=1=cs08130001045=cs2008=7992=2010-11-11=12:57=a.out
-rw-r--r--=1=cs08130001045=cs2008==502=2010-11-11=12:26=chterf.c
-rw-r--r--=1=cs08130001045=cs2008===22=2010-11-04=12:44=data.txt
-rw-r--r--=1=cs08130001045=cs2008====0=2010-11-11=13:29=list
-rw-r--r--=1=cs08130001045=cs2008==253=2010-09-23=15:33=logarithm
-rw-r--r--=1=cs08130001045=cs2008==106=2010-11-11=12:28=nfile
-rw-r--r--=1=cs08130001045=cs2008==262=2010-11-11=12:30=oddeven
drwxr-xr-x=2=cs08130001045=cs2008=4096=2010-09-23=15:18=Sun
-rw-r--r--=1=cs08130001045=cs2008=1171=2010-11-11=12:38=test.c
-rw-r--r--=1=cs08130001045=cs2008=1171=2010-11-11=12:38=text.c

Submit "Shell Script To Check Your Home Directory To display Files, Directories, and Sub-Directories Count" to Digg Submit "Shell Script To Check Your Home Directory To display Files, Directories, and Sub-Directories Count" to del.icio.us Submit "Shell Script To Check Your Home Directory To display Files, Directories, and Sub-Directories Count" to StumbleUpon Submit "Shell Script To Check Your Home Directory To display Files, Directories, and Sub-Directories Count" to Google

Updated 12-04-2011 at 07:00 PM by Harsh

Categories
Unix

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.