Display the number of files in a directory and recursively in each subdirectory


 
Thread Tools Search this Thread
Operating Systems Solaris Display the number of files in a directory and recursively in each subdirectory
# 1  
Old 05-09-2012
Display the number of files in a directory and recursively in each subdirectory

Display the number of files in a directory and recursively in each subdirectory

To look something like below, for example

Code:
/var          35
/var/tmp    56
/var/adm   46

Any ideas how can we do this?

Got a sun cluser global mount point which takes ages to mount everytime, need to understand the file distribution to see if we can split up the filesystem.

Last edited by methyl; 05-09-2012 at 07:41 PM.. Reason: Please use code tags. Correct spelling.
# 2  
Old 05-09-2012
That phrasing of the question sounds like homework/classroom stuff?
# 3  
Old 05-09-2012
Please define "number of files". Does it include directory files?
Please post what Operating System and version you have and what Shell you prefer.



Moderator's Comments:
Mod Comment Your previous identical post was closed. Is this a genuine commercial problem?
# 4  
Old 05-09-2012
You can do with something like:

Code:
for i in `find ./ -type d`;
do 
   echo $i `find $i -maxdepth 1 -type f|wc -l`;
done|cut -b 2-

Not very efficient but it works...

If I run it in my /usr

Code:
/ 0
/share 1
/share/opencc 23
/share/grub 7
/share/grub/default 2
/share/unity-2d 0
/share/unity-2d/shell 4
/share/unity-2d/shell/artwork 0
/share/unity-2d/shell/common 10
/share/unity-2d/shell/common/visibilityBehaviors 4
/share/unity-2d/shell/common/artwork 15
/share/unity-2d/shell/launcher 6
/share/unity-2d/shell/launcher/artwork 17
/share/unity-2d/shell/dash 33
/share/unity-2d/shell/dash/artwork 14
/share/unity-2d/shell/hud 2
/share/unity-2d/panel 0
/share/unity-2d/panel/applets 0
/share/unity-2d/panel/applets/appname 0
/share/unity-2d/panel/applets/appname/artwork 13
/share/unity-2d/spread 6
/share/libdbi-perl 1
/share/guile 0
/share/guile/1.8 1
/share/guile/1.8/oop 1
/share/guile/1.8/oop/goops 12
/share/guile/1.8/lang 0
/share/guile/1.8/lang/elisp 5
/share/guile/1.8/lang/elisp/internals 10
/share/guile/1.8/lang/elisp/primitives 19
/share/guile/1.8/ice-9 56
/share/guile/1.8/ice-9/debugger 5
/share/guile/1.8/ice-9/debugging 6
/share/guile/1.8/srfi 22
/share/xdiagnose 3
/share/xdiagnose/icons 1
/share/xdiagnose/workloads 16
/share/myspell 0
/share/myspell/infos 0
<truncated>


Last edited by methyl; 05-09-2012 at 07:36 PM.. Reason: Please use code tags.
# 5  
Old 05-09-2012
@juan.brein
What version of Solaris/SunOS do you have and what Shell are you using?
# 6  
Old 05-09-2012
I did it on bash under Linux, now I realize the Open Source "find" implementation has some options that Solaris doesn't, like -maxdepth...

You can use this alternative always using bash:

Quote:
for i in `find ./ -type d`;
do
echo $i `ls -l $i|/usr/xpg4/bin/grep -E '^-'|wc -l`;
done|cut -b 3-

Now on a Solaris 10 box under /usr:

/ 0
/lost+found 0
/share 3
/share/javadoc 0
/share/javadoc/smartcard 11
/share/javadoc/smartcard/com 0
/share/javadoc/smartcard/com/sun 0
/share/javadoc/smartcard/com/sun/smartcard 0
/share/javadoc/smartcard/com/sun/smartcard/scf 17
/share/javadoc/smartcard/resources 1
/share/javadoc/imq 14
/share/javadoc/imq/com 0
/share/javadoc/imq/com/sun 0
/share/javadoc/imq/com/sun/messaging 25
/share/javadoc/imq/com/sun/messaging/jms 21
/share/javadoc/imq/com/sun/messaging/xml 5
/share/javadoc/imq/javax 0
/share/javadoc/imq/javax/jms 61
/share/javadoc/imq/javax/xml 0
/share/javadoc/imq/javax/xml/messaging 12
/share/javadoc/imq/javax/xml/soap 28
/share/javadoc/imq/resources 1
/share/lib 11
/share/lib/jdmk 2
/share/lib/mailx 2
/share/lib/pub 4
/share/lib/tabset 10
/share/lib/terminfo 0
/share/lib/terminfo/3 18
/share/lib/terminfo/A 82
/share/lib/terminfo/a 289
<output truncated>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files recursively to one single directory

I need to copy a complete directory structure into a new location. But I want to have all files copied into one directory and leave out the directory structure. So all files must be placed in one directory. (4 Replies)
Discussion started by: ReneVL
4 Replies

2. Shell Programming and Scripting

How to recursively copy directory only for recent files?

I love the -newerct flag for the Cygwin find command on windows. Can I use "/usr/bin/find . -newerct '3 hours ago'" to conditionally copy a directory tree so that only the files in the directory tree that are younger than 3 hours are copied to my destination directory such that the directory... (4 Replies)
Discussion started by: siegfried
4 Replies

3. Shell Programming and Scripting

Remove all files except the subdirectory(without pattern) in a directory

I used rm * and it deleted the files in the directory but gives and error message for unsuccessful subdirectory deletion. "rm: cannot remove 'DirectoryName': Is a directory" I dont want to explicitly get the above error. What are the modifications I have to do in the rm command? (3 Replies)
Discussion started by: duplicate
3 Replies

4. Shell Programming and Scripting

Globbling files in the direct subdirectory of the current directory

I want to list files that end with .c in the direct subdirectory of the current directory. I have tried the following command: find ./ -mindepth 2 -maxdepth 2 -name "*.c" Is that right? Or is there any easier way to handle that problem? Another problem is that I want to grep in a file to find... (5 Replies)
Discussion started by: Ray Sun
5 Replies

5. Shell Programming and Scripting

Changing ownership of a directory, subdirectory and files as same as in another server

accidentally i have changed ownership of a directory,subdirectory and files wil below command. I want to the change ownership back as same as in same directory on another server. How can i do it? chown -R user:group /u01 is there any simple script? it is really an urgent need.. (2 Replies)
Discussion started by: johnveslin
2 Replies

6. Solaris

Display the number of files in a directory and recursively in each subdirectory

Display the number of files in a directory and recursively in each subdirectory To look something like below, for example /var 35 /var/tmp 56 /var/adm 46 Any ideas how can we do this? :wall: (1 Reply)
Discussion started by: jakerock
1 Replies

7. Shell Programming and Scripting

Move all files not in a directory into a subdirectory named for each given file

Hi Everyone! Looking for some help with a script that will take all files in any given root folder (which are not already in a folder) and put them into separate folders with the name of each given file. Any ideas? Thank you! (1 Reply)
Discussion started by: DanTheMan
1 Replies

8. UNIX for Dummies Questions & Answers

How to move all files in a directory and subdirectory?

I'm trying to organize my MB Pro by moving all my jpeg files to a single folder from the desktop. There are some on the desktop that are not in any folder. I was at the command line and typed mv *.jpg "Jpeg files" but it only moved the files that were on the desktop, not any of the ones that... (3 Replies)
Discussion started by: Straitsfan
3 Replies

9. Shell Programming and Scripting

delete files recursively in the specified directory

I have to write a shell script which can delete all the files and directories recursively inside the specified directory but should not delete the specified directory. Please some body help me in writing the script. (3 Replies)
Discussion started by: deepthi.s
3 Replies

10. Shell Programming and Scripting

Find files in directory and its subdirectory

I am writing a script which reads a file line by line and then assigns it to a variable like this 1090373422_4028715212.jpg. I have images with file name of this format in some other directory. In my script I want to assign variable with this file name and then find this filename in some other... (11 Replies)
Discussion started by: jyotib
11 Replies
Login or Register to Ask a Question

Featured Tech Videos