Results 1 to 5 of 5

Thread: du - different results when comparing macOS and Linux directories

  1. #1
    Join Date
    Nov 2017
    Beans
    20

    du - different results when comparing macOS and Linux directories

    Hi everyone,

    I have two supposedly identical directories on macOS (HFS+) and Ubuntu Server 20.04 (EXT4). I copied the directory from the Mac to the Linux machine using
    Code:
    rsync -auv [directory1] user@192.168.0.20:[directory2] 
    without problems. Now I have some problems with differing sizes of those two directories. Lets start with this:

    On the Linux machine, when my path is inside [directory2], I do
    Code:
    ls | wc -l
    , I get
    Code:
    147296
    as a result for the number of files in the directory
    Code:
    du -shk
    , I get
    Code:
    146460120
    as a result in kB

    On the Mac, inside [directory1], I do the same
    Code:
    ls | wc -l
    , I get
    Code:
    147296
    as a result for the number of files in the directory
    Code:
    du -shk
    , I get
    Code:
    149033768
    as a result in kB

    To explain the size difference, on the Linux machine I tried
    Code:
    du -shk --exclude './.*'
    to exclude hidden files and resource files, I get
    Code:
    146445092
    as a result in kB

    same on the Mac:
    Code:
    du -shk -I './.*'
    to exclude hidden files and resource files, I get
    Code:
    149033768
    as a result in kB, same as before

    When I do a
    Code:
    diff -x '.*' -rq [dir1] [dir2]
    it ends without output, so seemingly the same.

    What could explain the size differences? Or is there a better way to compare file sizes?
    Last edited by gebseng; August 2nd, 2020 at 07:53 PM.

  2. #2
    Join Date
    Jun 2018
    Beans
    68

    Re: du - different results when comparing macOS and Linux directories

    The difference may be related to a difference in size of file system entries and extra space allocated for sparse files. Try command "du -sb" to get the apparent byte size instead of a block size.

  3. #3
    Join Date
    Nov 2017
    Beans
    20

    Re: du - different results when comparing macOS and Linux directories

    Thanks! on the Ubuntu machine,
    Code:
    du -sb
    gives an output of 149672510341.

    On the Mac, I get a
    Code:
    du: illegal option -- b
    error. The macOS -du manpage states
    -h "Human-readable" output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte.
    , but I'm not sure how to use this.

  4. #4
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,052
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: du - different results when comparing macOS and Linux directories

    Try this instead of -b then:
    Code:
    du -s --apparent-size

  5. #5
    Join Date
    Apr 2020
    Beans
    67

    Re: du - different results when comparing macOS and Linux directories

    --Mac HFS+ does not support sparse files. As long as the number of files are the same, and they pass a basic md5sum / sha1sum check, it could be the difference between 512 sector size and 4096 on the different drives. And HFS+ just stores files a little differently.

    REF:
    https://en.wikipedia.org/wiki/HFS_Plus

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •