{"id":475,"date":"2012-07-04T16:48:27","date_gmt":"2012-07-04T08:48:27","guid":{"rendered":"http:\/\/rmohan.com\/?p=475"},"modified":"2012-07-04T16:48:27","modified_gmt":"2012-07-04T08:48:27","slug":"find-directory-with-biggest-number-of-files-directories","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=475","title":{"rendered":"Find directory with biggest number of files \/ directories"},"content":{"rendered":"<p><strong>Find directory with biggest number of files \/ directories<\/strong><\/p>\n<p>Today we had a problem related with a number of files in a directory. We needed to find directories with a biggest number of files \/ directories in it. Here is a small shell script that will list directories and a number of files\/directories in each directory.<\/p>\n<p>find . -type d|awk {&#8216;print &#8220;echo -n &#8220;$1&#8243;.\\&#8221;\\t\\&#8221;; ls &#8220;$1&#8243;|wc -l&#8221;&#8216;} &gt; \/tmp\/do; . \/tmp\/do|sort -k 2 -n -r |more<\/p>\n<p>Explaining it a little bit:<\/p>\n<p>&#8220;find . -type d&#8221; &#8211; find all directories bellow current directory<br \/>\n&#8220;awk {&#8216;print &#8220;echo -n &#8220;$1&#8243;.\\&#8221;\\t\\&#8221;; ls &#8220;$1&#8243;|wc -l&#8221;&#8216;} &gt; \/tmp\/do&#8221; &#8211; generate a script that will print a directory name (echo -n), make ls in this directory and count a number of lines from ls (wc -l)<br \/>\n&#8220;. \/tmp\/do&#8221; &#8211; execute generated script<br \/>\n&#8220;sort -k 2 -n -r&#8221; &#8211; sort the result using second column (-k 2) as numerical (-n) and in reverse order (-r)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find directory with biggest number of files \/ directories<\/p>\n<p>Today we had a problem related with a number of files in a directory. We needed to find directories with a biggest number of files \/ directories in it. Here is a small shell script that will list directories and a number of files\/directories in each [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/475"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=475"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":477,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions\/477"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}