2

I need to calculate the size of "real" files created under a folder (and its sub-folders) on an NTFS drive, where "real" is all files that are not present because of hard/soft-links, junctions etc.

Is there currently any tool that will do this? (command-line or graphical)

More details:

I guess such a capability will be useful only under the right circumstances, so, to avoid questions due to speculations on how I "really want to use it", I'll mention my use case in advance...

I've started using pnpm and I'm trying to evaluate actual disk usage. Given that the node_modules folder (when created by pnpm) contains folders that are links to pnpm's store, I know that files in those folders should not be counted. WinDirStat seems to ignore these folders, but I need to be sure about this.

Update (2019/12/02):

It seems to be more complicated than I thought. See this issue: Add size/disk usage benchmarks.

Doc
  • 121
  • 4

3 Answers3

0

Won't something like this work for you?

(Get-ChildItem -Recurse 'node_modules' | 
? { $_.LinkType -eq $Null } | 
Measure-Object -Sum Length).Sum

$_.LinkType -eq $Null filters out all link types.

ᄂ ᄀ
  • 208
0

using du isn't enough to not chase links. you can use this code :

find /home/somedirectory/ -exec du -s {} + | awk '{total = total + $1}END{print (total / 1024 / 1024) "MB"}'
Ali
  • 101
0

One way to do this would be to use FSCTL_GET_NTFS_FILE_RECORD. Links are properties of the file record.

As a bonus, it will enumerate things that the dir command won't show ($MFT, $LogFile, etc).