Looking for a tool to visualize folders based on number of files.

2 years ago by isti115 to c/linux

There are plenty of utilities (GUI, such as filelight and TUI, such as dua as well) for analyzing disk usage by space, but I would like to view my folders based on the count of files, as I'm making backups, and folders with lots of small files (e.g. node_modules) take very long to move around, so I guess that I'd be better of compressing those into a single file before archiving, as it's already highly unlikely that I'll need to access them anyway. Thanks for any pointers in advance!

d3Xt3r 15 points 2 years ago

You can use ncdu for this. Launch it with the options --show-itemcount --sort=itemcount

path: 0 7767067, hotness: undefined, score: 15, children: 1
isti115 3 points 2 years ago

Oh, wow, thank you! I had ncdu installed, but it was an older version, which didn't yet have this feature. Now that I updated to the newest (Zig based 🎉) release this looks perfect for my needs!

path: 0 7767067 7786251, hotness: undefined, score: 3, children: 0
mvirts 6 points 2 years ago

du --inodes | sort -h

maybe?

path: 0 7767489, hotness: undefined, score: 6, children: 1
isti115 3 points 2 years ago

Thank you for the idea! I didn't know about the --inodes flag before, this seems like a viable solution for systems where I can't / don't want to install additional software!

path: 0 7767489 7786295, hotness: undefined, score: 3, children: 0
palordrolap 3 points 2 years ago

Cinnamon's Nemo (GUI) file manager shows folder item count in the List View's "Size" column rather than a byte value. It started as a fork of Nautilus (now GNOME Files), so that and its descendents may also have the same feature.

The equivalent GNOME gio list command line command doesn't seem to do this.

It wouldn't be too hard to whip something up in Python, Perl etc. if you can't or don't want to install anything else for some reason.

e.g.

perl -wle '$a=$ARGV[0];opendir D, defined $a && -d $a?$a:".";@x=readdir D; print -2+@x'

is a Perl incantation that will return the number of entries in the current directory, or the supplied directory if that's added as a parameter after the command.

The -2 in there subtracts the count for . and ... That's off by one for the root directory where there's no ".." but that's rare and I didn't want to add too much for a quick proof of concept.

path: 0 7767978, hotness: undefined, score: 3, children: 2
isti115 1 point 2 years ago

Thanks for your input! To me it seems like Nemo only counts the direct descendants and doesn't recurse, which makes it less useful for this purpose, but still nice to know!

path: 0 7767978 7786427, hotness: undefined, score: 1, children: 1
palordrolap 1 point 2 years ago

The find command could be your friend for getting a full depth count. Something like:

find /path/name/here/ | wc -l

Or just:

find . | wc -l

for the current directory.

There's also a command called locate (often with another letter in front, but accessible by just that word) which maintains a database of filenames on a system that can be used, provided it's installed and has built that database.

Pro: Faster than churning the disk every time with find. (Though disk cache can help alleviate some of this).

Cons: Can get out of date with a changing filesystem. Harder to search for relative paths like .

locate -r '^/path/name/here/' | wc -l

... would be roughly equivalent to the first find example.

path: 0 7767978 7786427 7790471, hotness: undefined, score: 1, children: 0
BCsven 3 points 2 years ago path: 0 7773824, hotness: undefined, score: 3, children: 0
rlychilplr 1 point 2 years ago
path: 0 7767154, hotness: undefined, score: 1, children: 0
kylian0087 1 point 2 years ago

ncdu ?

path: 0 7792781, hotness: undefined, score: 1, children: 0
linux
linux

@lemmy.ml

login for more options
67095
9204
4151

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

  • Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
  • No misinformation
  • No NSFW content
  • No hate speech, bigotry, etc

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

go to feed...