English English

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​

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.

Ok