|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Number of files in all (sub-)directories
Hi,
I need a list of the number of files in all (sub-)directories e.g.: /a/b/c 1364 /a/b 125 /a 362 etc. Should be nice to have the list sorted from high to low. Regards, Wim |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
One way.. (Include the highlighted part for high to low) Code:
$ find /dir/location -type f | nawk -F\/ '{$NF=""; print}' OFS=\/ | sort | uniq -c | sort -nr |
| The Following User Says Thank You to jayan_jay For This Useful Post: | ||
deleriumdog (06-29-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Have you considered finding all the directories and then counting the files of each from there:- Code:
for dir in `find $top_dir -type d | sort` do echo "$dir \c" find $dir -type f | wc -l done | sort -nr +1 That will give you al the files from each directory and below, but of course the higher directories will have all the subdirectories included, so might not be what you want. If you need to , then perhaps you could sort this output and then for each directory, reduce the count by any direct subdirectories (i.e. take away /a/b from /a, but ignore /a/b/c) Does this help at all, or have I missed the point? Robin Liverpool/Blackburn Last edited by rbatte1; 06-19-2012 at 09:19 AM.. Reason: Added sort |
|
#4
|
|||
|
|||
|
Hi jayan_jay,
This works, thanks! Can you please add the total number of bytes in this directory on the same row as well? |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
Code:
for dir in `find $top_dir -type d | sort` do echo "$dir `find $dir -type f | wc -l` `du -ks $dir`" done | sort -nr +1 Is that any good? This gives you the Kb for each directory on it's own. If you want to count all Kb from each directory and all sub-directories, drop the s flag from the du command. Robin Liverpool/Blackburn UK Last edited by rbatte1; 06-19-2012 at 09:48 AM.. Reason: Clarification of du |
| The Following User Says Thank You to rbatte1 For This Useful Post: | ||
deleriumdog (06-29-2012) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
@rbatte1,
Can you add this in the command from jayan_jay? Many thanks, Wim |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Code:
$ find dir_path -type f -exec ls -ltr {} \; | nawk -F\/ '{$NF=""; print}' OFS=\/ |
nawk '{a[$NF]++ ; b[$NF]=b[$NF]+$5}END{for(i in a) print(i, a[i], b[i])}' |
| The Following User Says Thank You to jayan_jay For This Useful Post: | ||
deleriumdog (06-29-2012) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with examine the number files in directories given as arguments | abo-el-sos | Shell Programming and Scripting | 1 | 04-22-2011 07:00 AM |
| List directories and sub directories recursively excluding files | pointers | UNIX for Dummies Questions & Answers | 3 | 02-23-2011 08:39 PM |
| How to get number of files and directories? | raju110384 | UNIX for Dummies Questions & Answers | 4 | 12-12-2010 06:13 AM |
| Help with command to Move files by X number to seperate directories | Geo_Bean | Shell Programming and Scripting | 8 | 03-26-2010 06:10 AM |
| Bash scripting to compare N number of files located in two directories | Sangtha | Shell Programming and Scripting | 2 | 07-08-2009 02:48 PM |
|
|