My goal is rather simple: I want to create a small database of all files/directories within a big directory.
After looking for a tool suited I couldn't find anything but the good ol' du
. I figured out that I should use -b
if I want the number of bytes the files actually have and to use -a
to list all files. Great.
Now here's the problem: I do not want to include directories in du
's output. I would like to have the output like this per file: size<tab>filename
so I can convert this to CSV or some kind of database. The problem with it containing directories would be that I wouldn't know how to separate directories from files after when I convert/import it to a database and I don't want to end up having files accidentally as directories or vice-versa. I also don't want to end up accidentally counting too much total usage space because when I sum up all files in a directory I already get the whole directory's size, if I add the size of the entire directory on top of that it would be too much.
Here is why I don't want to use find -type f
... (test directory with 38k files in total, the real one has millions)
$ time find -mindepth 1 -type f -exec du -sb {} > /dev/null \;
real 0m45.631s
user 0m25.807s
sys 0m18.946s
$ time du -ab > /dev/null
real 0m0.154s
user 0m0.057s
sys 0m0.096s
I'm open to suggestions of any other way to achieve my initial goal. I just need a way in the end to "browse" directories and see their sizes (and the sizes of the files they contain) without actually having the filesystem in question mounted. (So kinda like an "offline" baobab you might say)