Display the folders with the most number of files and folders - Shell script

You can display the folders that have the most amount of files and folders with this Shell script. In Linux you have a limited numbers of inodes and this can be a problem if you have too much of files, especially if they are very small and you have a limited disk space.

This shell script displays the absolute path to the folders with the most amount descending. All files on the operating system will be searched.

find / -xdev -type d -print0 |
  while IFS= read -d '' dir; do
    echo "$(find "$dir" -maxdepth 1 -print0 | grep -zc .) $dir"
  done |
  sort -rn |
  head -50​

Give the script executable rights and run it. It will take some time to display the results.

chmod +x ./my_script.sh && ./my_script.sh​
Cookies make it easier for us to provide you with our services. With the usage of our services you permit us to use cookies.