Sample Header Ad - 728x90

Exclude directories for du command / Index all files in a directory

1 vote
1 answer
3331 views
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: sizefilename 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)
Asked by confetti (2134 rep)
Dec 26, 2020, 05:26 AM
Last activity: Dec 27, 2020, 09:38 AM