1

I'm trying to clean up my hard drive to recover some disk space. Part of what I'm doing is merging two large directories of image files that I know have lots of duplicates because they were two copies originated from the same set of files. The two directories are quite large so I moved (mv) one to an external hard drive first. Then I used rsync to copy/merge the two folders

rsync -thrivpb '/Volumes/external_harddrive/image_temp/' '/Users/glds/image'

Then I noticed a lot of resource fork files with the file names ._XXX were also being copied over. I suspect that many of those are not necessary. Is there a way to safely clean up unnecessary resource files in the destination folder now?

I've searched on Internet and couldn't find a good and recent enough reference that I feel comfortable to follow.

Two tentative approaches I'm considering:

  • Find and delete all resource files using find:

    find . -type f -iname '._*' -exec rm '{}' \;
    

    But some references, potentially outdated and invalid though, do recommend against simply deleting resource files. So I'm not sure.

  • Use the dot_clean command to merge the resource fork to its corresponding file. I found a 10-year old reference at https://discussions.apple.com/thread/5192627 on this approach which essentially uses

    dot_clean -m 
    

However, I'm unable to follow its exact instruction as the "Service" mentioned in the step "Select Service as the type of workflow" is no longer available in macOS 13's Automator.

  • Update 1: The external hard drive is ExtFAT. The main hard drive where image/ is is APFS.
10
  • 1
    What kind of attributes are you talking about? Stuff like Finder info, custom icons, tags, and labels probably wouldn't be an issue, but some older formats stored the actual image data in the resource fork.
    – red_menace
    Nov 17, 2023 at 19:47
  • @red_menace: I don't know how to check.
    – qazwsx
    Nov 17, 2023 at 19:56
  • The answer with respect to dot_clean depends on the format of the volume where the files reside. For example, the dot_clean command with the same parameters could perform a different operation on a JHFS+ formatted volume versus a FAT32 formatted volume. Nov 17, 2023 at 22:28
  • 1
    I suspect that the amount of space you will free up by deleting resource forks will be ooh, maybe as much as tens of Megabytes. And the risk of deleting something useful or crucial is large.
    – benwiggy
    Nov 18, 2023 at 10:18
  • @benwiggy: I fail to see how the amount of space that you will free up by deleting resource forks has any relevancy to the OP's question. The use of rsync was used to recover some disk space. The desire to delete resource forks was not done in an effort to recover some additional disk space. Nov 20, 2023 at 5:38

1 Answer 1

2

The dot_clean operations can depend on the file system. I will try to illustrate this through examples. Basicaly, the following will be shown.

  • The find . -type f -iname '._*' -exec rm '{}' \; command does the same thing as the dot_clean -m --keep=native . command, which is to remove ._* files.
  • The dot_clean -m . command also removes ._* files, but can also transfer information before removing the files.

Initial Conditions

The ls command output below shows the contains of four volumes which are formatted as FAT32, APFS, ExFAT and JHFS+. The data fork of the hi.txt file in each volume is the same. The same is true for the ._bye.txt and ._hi.txt files in each volume. All previously existing bye.txt files have been removed.

davidanderson@Snapper /Volumes % ls -l@OeA /Volumes/MYFAT32 /Volumes/MyAPFS /Volumes/MyExFAT /Volumes/MyJHFS+   
/Volumes/MYFAT32:
total 32
-rwxrwxrwx  1 davidanderson  staff  hidden 4096 Nov 17 17:04 ._bye.txt
-rwxrwxrwx  1 davidanderson  staff  hidden 4096 Nov 17 17:02 ._hi.txt
drwxrwxrwx  1 davidanderson  staff  hidden 4096 Nov 17 18:49 .fseventsd
-rwxrwxrwx@ 1 davidanderson  staff  -        10 Nov 17 17:02 hi.txt
    com.apple.TextEncoding    15 
    com.apple.lastuseddate#PS     16 
    com.apple.metadata:kMDLabel_df4faouox2jis4jyu5u6pu7qnu    89 

/Volumes/MyAPFS:
total 24
-rwxrwxrwx  1 davidanderson  staff  - 4096 Nov 17 17:04 ._bye.txt
-rwxrwxrwx  1 davidanderson  staff  - 4096 Nov 17 17:02 ._hi.txt
drwxrwxrwx  7 davidanderson  staff  -  224 Nov 17 17:17 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -   10 Nov 17 17:02 hi.txt

/Volumes/MyExFAT:
total 256
-rwxrwxrwx  1 davidanderson  staff  hidden  4096 Nov 17 17:04 ._bye.txt
-rwxrwxrwx  1 davidanderson  staff  hidden  4096 Nov 17 17:02 ._hi.txt
drwxrwxrwx  1 davidanderson  staff  hidden 32768 Nov 17 18:49 .fseventsd
-rwxrwxrwx@ 1 davidanderson  staff  -         10 Nov 17 17:02 hi.txt
    com.apple.TextEncoding     15 
    com.apple.lastuseddate#PS      16 
    com.apple.metadata:kMDLabel_df4faouox2jis4jyu5u6pu7qnu     89 

/Volumes/MyJHFS+:
total 24
-rwxrwxrwx  1 davidanderson  staff  - 4096 Nov 17 17:04 ._bye.txt
-rwxrwxrwx  1 davidanderson  staff  - 4096 Nov 17 17:02 ._hi.txt
drwxrwxrwx  7 davidanderson  staff  -  238 Nov 17 17:17 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -   10 Nov 17 17:02 hi.txt

Note the following:

  • The hi.txt file in the FAT32 and ExFAT volumes has extended attributes which are stored in the ._hi.txt file.
  • The hi.txt file in the APFS and JHFS+ volumes has no extended attributes. The extended attributes, which are stored in the ._hi.txt file, are ignored.

Case 1: Use of find . -type f -iname '._*' -exec rm '{}' \;

Below the find . -type f -iname '._*' -exec rm '{}' \; command was modified to act on the four volumes as given in the Initial Conditions section. The results are shown below.

davidanderson@Snapper /Volumes % find /Volumes/MYFAT32 /Volumes/MyAPFS /Volumes/MyExFAT /Volumes/MyJHFS+ -type f -iname '._*' -exec rm '{}' \;
davidanderson@Snapper /Volumes % ls -l@OeA /Volumes/MYFAT32 /Volumes/MyAPFS /Volumes/MyExFAT /Volumes/MyJHFS+
/Volumes/MYFAT32:
total 16
drwxrwxrwx  1 davidanderson  staff  hidden 4096 Nov 17 18:49 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -        10 Nov 17 17:02 hi.txt

/Volumes/MyAPFS:
total 8
drwxrwxrwx  7 davidanderson  staff  - 224 Nov 17 17:17 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -  10 Nov 17 17:02 hi.txt

/Volumes/MyExFAT:
total 128
drwxrwxrwx  1 davidanderson  staff  hidden 32768 Nov 17 18:49 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -         10 Nov 17 17:02 hi.txt

/Volumes/MyJHFS+:
total 8
drwxrwxrwx  7 davidanderson  staff  - 238 Nov 17 17:17 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -  10 Nov 17 17:02 hi.txt

Note the following:

  • All ._* files have been removed.
  • None of the hi.txt files have extended attributes.

Case 2: Use of dot_clean -m .

Below the dot_clean -m . command was modified to act on the four volumes as given in the Initial Conditions section. The results are shown below.

davidanderson@Snapper /Volumes % dot_clean -m /Volumes/MYFAT32 /Volum/MyAPFS /Volumes/MyExFAT /Volumes/MyJHFS+
davidanderson@Snapper /Volumes % ls -l@OeA /Volumes/MYFAT32 /Volumes/MyAPFS /Volumes/MyExFAT /Volumes/MyJHFS+
/Volumes/MYFAT32:
total 16
drwxrwxrwx  1 davidanderson  staff  hidden 4096 Nov 17 19:32 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -        10 Nov 17 17:02 hi.txt

/Volumes/MyAPFS:
total 16
drwxrwxrwx  7 davidanderson  staff  - 224 Nov 17 17:17 .fseventsd
-rwxrwxrwx@ 1 davidanderson  staff  -  10 Nov 17 17:02 hi.txt
    com.apple.ResourceFork  286 
    com.apple.TextEncoding   15 
    com.apple.lastuseddate#PS    16 
    com.apple.metadata:kMDLabel_df4faouox2jis4jyu5u6pu7qnu   89 

/Volumes/MyExFAT:
total 128
drwxrwxrwx  1 davidanderson  staff  hidden 32768 Nov 17 19:32 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -         10 Nov 17 17:02 hi.txt

/Volumes/MyJHFS+:
total 16
drwxrwxrwx  7 davidanderson  staff  - 238 Nov 17 17:17 .fseventsd
-rwxrwxrwx@ 1 davidanderson  staff  -  10 Nov 17 17:02 hi.txt
    com.apple.ResourceFork  286 
    com.apple.TextEncoding   15 
    com.apple.lastuseddate#PS    16 
    com.apple.metadata:kMDLabel_df4faouox2jis4jyu5u6pu7qnu   89 

Note the following:

  • All ._* files have been removed.
  • The hi.txt file in the FAT32 and ExFAT volumes has no extended attributes.
  • The hi.txt file in the APFS and JHFS+ volumes has extended attributes. The extended attributes were copied from the ._hi.txt file before the ._hi.txt file was removed.

Case 3: Use of dot_clean -m --keep=native .

Below the dot_clean -m --keep=native . command was modified to act on the four volumes as given in the Initial Conditions section. The results are shown below.

davidanderson@Snapper /Volumes % dot_clean -m --keep=native /Volumes/MYFAT32 /Volumes/MyAPFS /Volumes/MyExFAT /Volumes/MyJHFS+
davidanderson@Snapper /Volumes % ls -l@OeA /Volumes/MYFAT32 /Volumes/MyAPFS /Volumes/MyExFAT /Volumes/MyJHFS+                
/Volumes/MYFAT32:
total 16
drwxrwxrwx  1 davidanderson  staff  hidden 4096 Nov 17 19:37 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -        10 Nov 17 17:02 hi.txt

/Volumes/MyAPFS:
total 8
drwxrwxrwx  7 davidanderson  staff  - 224 Nov 17 17:17 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -  10 Nov 17 17:02 hi.txt

/Volumes/MyExFAT:
total 128
drwxrwxrwx  1 davidanderson  staff  hidden 32768 Nov 17 19:37 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -         10 Nov 17 17:02 hi.txt

/Volumes/MyJHFS+:
total 8
drwxrwxrwx  7 davidanderson  staff  - 238 Nov 17 17:17 .fseventsd
-rwxrwxrwx  1 davidanderson  staff  -  10 Nov 17 17:02 hi.txt

Note the following:

  • All ._* files have been removed.
  • None of the hi.txt files have extended attributes.
  • The results are the same as Case 1.

macOS Catalina version 10.15.7 was used to test this answer.


Creating and Attaching (Mounting) a Sparse Disk Image File.

The problems posted in the question could have been avoided by create an APFS formatted sparse image on the external ExFAT formatted drive.

  1. Open the Disk Utility application.

  2. From the menu bar, select File > New Image > Blank Image...

  3. Fill out the popup. An example is given below.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .