Print the directory with the most files in unix/linux -


i'm new stack overflow, patient.

i'm in directory contains both files , directories. want command print out name of directory (out of few specified directories) has greatest number of files in it.

here go:

for d in */ ; echo "$d" $(find $d -type f | wc -l); done | sort -n -k 2 

explanation:

for d in *  

loop through directories only

echo "$d" $(find $d -type f | wc -l)  

show directory name , count of files (recursively)

sort -n -k 2 

sort numerically output of whole thing (for loop) using second field (the number of files)


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -