Directories with maximum number of files

2018-12-10 72 words 1 min read

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  ----------

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it