Operating System - HP-UX
1833784 Members
4207 Online
110063 Solutions
New Discussion

How to list directory/sub with No. of files

 
SOLVED
Go to solution
Ahmed_58
Regular Advisor

How to list directory/sub with No. of files

Hi,
How can I display directores & sub direcoryes (TREE) showing No. of files? will be nice to have size of each directory on the same list.

Example:

/abc 1234 10
/abc/efg 233 20
- -
- -
Thanks,
Ahmed
12 REPLIES 12
RAC_1
Honored Contributor

Re: How to list directory/sub with No. of files

There was such a scrit posted on forum some days back. Search for it.
There is no substitute to HARDWORK
Arunvijai_4
Honored Contributor

Re: How to list directory/sub with No. of files

Hi Ahmed,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=875309

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: How to list directory/sub with No. of files

Use this:

# Change here
DIRECTORY="/tmp"
echo "Size Directory File Count"
for dir in `find ${DIRECTORY} -type d`
do
count=$(find $dir -type f | wc -l)
echo "$(du -ks $dir) $count"
done

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: How to list directory/sub with No. of files

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=875309

is dealing with file counts in a file system. If you want to get directories & sub directories with file count and size then you have to use find and du to get this.

--
Muthu
Easy to suggest when don't know about the problem!
Devender Khatana
Honored Contributor

Re: How to list directory/sub with No. of files

Hi,

Another similat thread
http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=117611

HTH,
Devender
Impossible itself mentions "I m possible"
Ahmed_58
Regular Advisor

Re: How to list directory/sub with No. of files

Hi Muthukumar..
Can you check the scripts, it is not working with me...
I need to list directory names with file count.

Thanks,
Ahmed
Arunvijai_4
Honored Contributor

Re: How to list directory/sub with No. of files

Hi Ahmed,

How about this command ?

# find dir_path -depth -type f -print | wc -l

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: How to list directory/sub with No. of files

what is the error you are getting? can you please elloborate the issue with script?

--
Muthu
Easy to suggest when don't know about the problem!
Ahmed_58
Regular Advisor

Re: How to list directory/sub with No. of files

dear Muthukumar,
I'm not good in scripting ....
The error I'm getting as example ....

Size Directory File Count
./ahmed[3]: Syntax error at line 3 : `for' is not matched.

SCRIPT:
--------------------------
DIRECTORY="/tmp"
echo "Size Directory File Count"
for dir in `find ${DIRECTORY} -type d`
do
count=$(find $dir -type f | wc -l)
echo "$(du -ks $dir) $count"
----------------------------

Regards,
Ahmed

Muthukumar_5
Honored Contributor
Solution

Re: How to list directory/sub with No. of files

There is a problem in second find loop. It will count files in inner level directories too. To avoid that use as,

#!/bin/ksh

# Change here - User input
DIRECTORY="/tmp"

echo "Size Directory File-Count"
for dir in `find ${DIRECTORY} -type d`
do
count=$(ls -l $dir | grep -E '^-' | wc -l)
echo "$(du -ks $dir) $count"
done

# END
exit 0

########

--
Muthu
Easy to suggest when don't know about the problem!
Ahmed_58
Regular Advisor

Re: How to list directory/sub with No. of files

Muthu,

Thanks that's exactley what I'm looking for.

have a nice day.
Regards,
Ahmed
Ahmed_58
Regular Advisor

Re: How to list directory/sub with No. of files

# Change here - User input
DIRECTORY="/tmp"

echo "Size Directory File-Count"
for dir in `find ${DIRECTORY} -type d`
do
count=$(ls -l $dir | grep -E '^-' | wc -l)
echo "$(du -ks $dir) $count"
done

# END
exit 0