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​

Usamos cookies en nuestro sitio web. Algunas de ellas son esenciales para el funcionamiento del sitio, mientras que otras nos ayudan a mejorar el sitio web y también la experiencia del usuario (cookies de rastreo). Puedes decidir por ti mismo si quieres permitir el uso de las cookies. Ten en cuenta que si las rechazas, puede que no puedas usar todas las funcionalidades del sitio web.