Directories with maximum number of files

2018-12-10 1 min read bash

Lot of times, I want to find the directories with maximum number of files and so I wrote this quick function to do exactly the same

 

function count_lines ()
{
    oldIFS=$IFS
    count=0
    IFS=$'\n'
    dir=${1:-.}
    cd $dir
    find . -type d |while read line
    do
        echo -n "$(find $line -type f |wc -l) $line"
        echo 
        printf "Directories :: %8d\r" $count >&2
        ((count++))
    done|sort -n
    IFS=$oldIFS
}   # ----------  end of function count_lines  ----------
comments powered by Disqus