Sub directories containing maximum files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sub directories containing maximum files
# 1  
Old 06-20-2011
Sub directories containing maximum files

Hi All,

I have this command coded in C Shell to get the top ten sub directories in the order of number of files they contain.
Code:
find $parent_dir -type d -exec filecount {} \; | sort -nr | head -10

But it does not seem to show any output. Can someone please help me out in correcting this (preferably one liner command am expecting).

Thanks
-Durga

Last edited by Franklin52; 06-20-2011 at 09:15 AM.. Reason: Please use code tags for data end code samples.
# 2  
Old 06-20-2011
Code:
% du <DIR> | sort -nr | head -10

# 3  
Old 06-20-2011
Quote:
Originally Posted by yazu
Code:
% du <DIR> | sort -nr | head -10

But this will give the directories occupying maximum space. What my command is intended is to get the directories containing maximum number of files (size may be of smaller but count wise they will be high)
# 4  
Old 06-20-2011
Code:
$ Desktop/Scripts/dir_count.sh | sort -k 2 -nr | head -10
./.cache/google-chrome/Default/Cache 627
./sybaseDB/jConnect-6_0/docs/en/progref 198
./.compiz/session 183
./sybaseDB/shared/JRE-6_0_6_32BIT/lib/zi/America 110
./sybaseDB/jre32/lib/zi/America 110
./sybaseDB/charsets/unicode 94
./sybaseDB/jConnect-7_0/sample2 79
./sybaseDB/jConnect-6_0/sample2 79
./sybaseDB/shared/JRE-6_0_6_32BIT/lib/zi/Asia 78
./sybaseDB/jre32/lib/zi/Asia 78



$ cat Desktop/Scripts/dir_count.sh 
find . -type d | while read dir; do 
    count=$(find "$dir" -maxdepth 1 -type f | wc -l)
    echo "$dir $count"
done

# 5  
Old 06-20-2011
Excuse me. You need a simple program "filecount". Something like:
Code:
#!/bin/sh
echo $(ls $1 | wc -l) $1

Put this in file, name it "filecount", chmod +x filecount, put this command in your path (for example in $HOME/bin, and add $HOME/bin to PATH), then your find command should work.
# 6  
Old 06-20-2011
Thanks Yazu and itkamraj.
I missed the executable filecount. I was under the impression that filecount is a UNIX command. Found out the missing filecount script and now the command works fine. :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Debian

Problem with maximum files and directories

Hi, I'm using Kali linux, I think it's a debian linux ? I'm trying to create a folder in which there'll be 256 folders, and in each of this folders there will also be 256 folders. Then in each terminate folders I want to create 4096 files. It will look like /dir/aa/aa/aaa.txt,... (3 Replies)
Discussion started by: ganon551
3 Replies

2. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

3. Shell Programming and Scripting

Extracting files having maximum timestamp

Hi , I'm using Ksh 88 I've the following files in a directory with YearMonthDate (Ex:20130601) YDT:FILE1:20130601 YDT:FILE1:20130615 YDT:FILE2:20130601 YDT:FILE2:20130615 YDT:FILE3:20130601 YDT:FILE3:20130615 And i need the files having maximum timestamp , Means i need to display ... (8 Replies)
Discussion started by: smile689
8 Replies

4. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

5. Shell Programming and Scripting

How to store files/directories in different directories!!

Hi legends, I am writing a script, in that my requirement is, if all the fill types stored in one directory from that we need to separate different different directories based on the file types. for example in a directory(anish). 5 different types files 1- directory 2- .txt files 2- .sh... (1 Reply)
Discussion started by: anishkumarv
1 Replies

6. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

7. Linux

maximum file & directories

Dear friends, How many maximum number of files and directories can be created in linux system. Thanks.. (2 Replies)
Discussion started by: karthigayan
2 Replies

8. UNIX for Dummies Questions & Answers

ls - maximum number of files

what is the maximum number ls can list down (6 Replies)
Discussion started by: karnan
6 Replies

9. UNIX for Dummies Questions & Answers

Maximum files in a Directory

Does Solaris impose limits on : - the maximum number of files a directory can have, - total file size in a directory If there is such limits, how can I can check for each? Thanks...:confused: (1 Reply)
Discussion started by: deaniyoer
1 Replies
Login or Register to Ask a Question