Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

APFS and duplicate files

Hello.


If I copy two identical files from two different volumes on two different location of the same APFS volume, will they be duplicated ? And what if the identical files have different names ?


I could probably test it at home, but I don't know how to do it : Imagine I copy file1.odt on my usb drive to another.odt on a network drive. Then I create on my APFS drive two folders : USBFolder and NETFolder. I then copy file1.odt in USBFolder and another.odt in NETFolder. OK. Piece of cake.


Now for the tricky bit : How can I test wether the two files are on the disk or are just an instance of the same file ? And what should I expect from Mojave ?


Any ideas ?


TIA and best regards


Volny

MacBook (13-inch Late 2008)

Posted on Oct 29, 2018 12:56 PM

Reply
Question marked as Best reply

Posted on Oct 29, 2018 5:36 PM

What is it you think APFS will do for you.


APFS has Copy-on-Write copying. If you copy a file stored on APFS, and copy it to another folder on the same APFS file system, then APFS will create a new file marked Copy-on-Write, and point at all of the storage of the original file. But if you attempt ot modify either file, then the storage that is modified will be copied to new storage and the original will be given to the file that has not been modified.


They are 2 different files, but do not take up the storage of 1 file as long as they remain unchanged. Once you start changing one of them, you start to use more storage.


But you have to start with an APFS file and duplicate it to another location or a different name on the same APFS file system to get this benefit.


APFS does not try to figure out if existing files or files copied in from an outside source match anything already on the file system.

Similar questions

2 replies
Question marked as Best reply

Oct 29, 2018 5:36 PM in response to Volny

What is it you think APFS will do for you.


APFS has Copy-on-Write copying. If you copy a file stored on APFS, and copy it to another folder on the same APFS file system, then APFS will create a new file marked Copy-on-Write, and point at all of the storage of the original file. But if you attempt ot modify either file, then the storage that is modified will be copied to new storage and the original will be given to the file that has not been modified.


They are 2 different files, but do not take up the storage of 1 file as long as they remain unchanged. Once you start changing one of them, you start to use more storage.


But you have to start with an APFS file and duplicate it to another location or a different name on the same APFS file system to get this benefit.


APFS does not try to figure out if existing files or files copied in from an outside source match anything already on the file system.

Oct 29, 2018 4:06 PM in response to Volny

APFS doesn't support de-duplication at this level. If you copy a second instance of a file, you get two copies of the file on your disk. Editing one won't have any effect on the other.


That said, even without APFS, you can use the UNIX diff command to tell if two files contain identical data, and ls -I to display the inode data for files (hard links to the same file will have the same inode value):


$ touch file

$ ln file otherfile

$ cp file anotherfile

$ ls -il *file

18661571 -rw-r--r-- 1 andrewo staff 0 Oct 29 16:05 anotherfile

18661563 -rw-r--r-- 2 andrewo staff 0 Oct 29 16:04 file

18661563 -rw-r--r-- 2 andrewo staff 0 Oct 29 16:04 otherfile


Both file and otherfile have the same inode number and therefore are the same thing (created by a hard link), and anotherfile is a copy, but has a different inode.

APFS and duplicate files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.