Skip to main content
edited title
Link
IconDaemon
  • 19.6k
  • 10
  • 44
  • 60

MacOS macOS get a file's "allocated size" from terminal?

Source Link

MacOS get a file's "allocated size" from terminal?

I'm on a Macbook Pro running macOS 12.2.1 (so using the APFS filesystem.)

I noticed some strange behavior when creating a large "dummy file" using the mkfile utility. (/usr/sbin/mkfile)

I created a 5 GB file with the command:

mkfile -n 5g test.txt

Then, to confirm it worked, I ran the du command. (/usr/bin/du).

du -hs ./test.txt

But I got an unexpected outcome:

4.0K    ./test.txt

I went to the file in Finder and looked at the file info, and saw there were two different sizes. Top line highlighted displays the size as 5 Gigabytes. However, further down it displays the text: "4 KB on disk"

After some further digging, I found this info on the mkfile man page:

OPTIONS
     -n     Create an empty filename.  The size is noted, but disk blocks aren't
            allocated until data is written to them.

So I wanted to know, is there a command that will let me see the allocated file size?