Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Linux, how do I find find directory with the most subdirectories or files? [closed]

Tags:

linux

How can I find the directory with the largest number of files/subdirectories in it on the system? Obviously the clever answer is /, but that's not what I'm looking for.

I’ve been told the filesystem is out of nodes, so I suspect that somewhere there are a lot of files/directories which are just garbage, and I want to find them.

I’ve tried running this:

$ find /home/user -type d -print | wc -l

to find specific directories.

like image 566
anio Avatar asked Jun 12 '12 17:06

anio


People also ask

How do I search a directory and subdirectory in Linux?

Finding Files Recursively in Linux The find command does not need flags to search the files recursively in the current directory. You only need to define the main directory and the file name using the –name option. This command will search the file within the main directory and all subdirectories.

Which command is used to show the directory and all subdirectories of files?

The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags. If you do not specify a File or Directory, the ls command displays the contents of the current directory.

How do you get a list of all files in a directory and its subdirectories?

The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.


1 Answers

starting from the current directory, you could try

find . -type d | cut -d/ -f 2 | uniq -c

This will list all directories starting from the current one, split each line by the character "/", select field number "2" (each line starts with "./", so your first field would be ".") and then only outputs unique lines, and a count how often this unique line appears (-c parameter).

You could also add an "sort -g" at the end.

like image 127
niko Avatar answered Oct 23 '22 04:10

niko