246

I am using different operating systems on different machines on different locations. I am using a USB flash disk to keep my files (source codes etc.).

I am new to Mac OS X and now I realize there are lots of files created with a dot underscore ._ prefix.

Questions

Why are ._ files created?

What are their purpose?

How can I avoid them?

8
  • the issue is as @geekosaur says and so hard to avoid if you use Apple file tools. However if you only use command line tools and some 3rd party ones and never write to the USB with Finder they will not be created.
    – mmmmmm
    May 29, 2011 at 20:15
  • 4
    I dislike them too but I've learned to cohabitate with them peacefully.
    – boehj
    May 29, 2011 at 22:43
  • The behaviour is not limited to Apple software. Example: Microsoft Office 2011 requires ._ files when saving to file systems that are without support for HFS type codes and creator codes. May 12, 2012 at 4:09
  • 1
    If the flash drive is formatted in HFS+ format, that should suppress the creation of ._ files, but I don't know what options exist on your unspecified other operating systems to read HFS+ volumes.
    – Daniel
    May 12, 2012 at 5:36
  • 2
    Not ideal, but ls --ignore="._*" as an alias or keybinding goes a long way. Jun 30, 2016 at 3:20

13 Answers 13

167

You can't avoid them (but see the dot_clean answer by Saeid Zebardast --they can be removed from a directory if that is what you need). They're created to store file information that would otherwise go into an extended attribute on HFS+ (Apple native) or Unix/UFS volumes; in earlier Mac OS this would be the resource fork. Finder file operations will create them automatically to store the icon information, plus Time Machine stores some information in them so if you copy a file backed up via TM it will have that information copied as well.

(This is nothing new; I've noticed that XP and later leave various turds around as well, although not quite as many.)

9
  • 82
    I agree, "turd" is an accurate description :)
    – Drahcir
    Aug 1, 2014 at 12:46
  • 5
    I noticed that my Mac is leaving turds on my linux samba server when I use color labels (using Path Finder 7). There is a ._<coloreditem> file for each colored item. Dec 14, 2014 at 15:39
  • 11
    We have the same situation in our linux samba file server at work. Since we don't need color metadata for files, we used the veto files = /._*/ and delete veto files options in our smb.conf to prevent creation of such files. Instead we leave .DS_STORE files as they are, since they are useful to set file sorting, and there is only one of them for each dir.
    – gerlos
    May 18, 2015 at 18:15
  • 6
    At least on Windows you can turn this off!
    – totymedli
    Sep 3, 2015 at 0:22
  • 17
    Upvoted for use of "turds" to describe this.
    – George P
    Nov 18, 2015 at 4:31
122

You can use dot_clean command to remove or merge the ._ files:

dot_clean PATH_OF_FOLDER_OR_DRIVE

If you move files to linux, or have Git Bash on your PC, and have access to the find command, you might also be able to do this:

find . -type f -name '._*' -delete

And they're gone!

5
  • 5
    The other answers don't really answer the "How can I avoid them?" part. This does. Thanks!
    – Haru
    Apr 25, 2016 at 16:26
  • 23
    From man dot_clean: For each dir, dot_clean recursively merges all ._* files with their corresponding native files according to the rules specified with the given arguments. By default, if there is an attribute on the native file that is also present in the ._ file, the most recent attribute will be used. This command does not just remove certain dot files, it may overwrite previous / native attributes for each folder. Use with caution. May 26, 2016 at 8:15
  • 3
    Not sure if its been mentioned here or not but please be careful in removing bulk amounts of ._ files. They might remove file/folder icons, comments, labels etc. Be sure that wherever youre removing them this is not an issue
    – leetbacoon
    Oct 14, 2019 at 18:51
  • I tried the mentioned command except the -delete portion, it included loadash._reinterpolation directory too.
    – ssi-anik
    Dec 24, 2020 at 11:19
  • 4
    I'd probably add a size test find . -type f -name '._*' -size -4k, I forget how big they are
    – CervEd
    Apr 22, 2021 at 8:16
43

Purposes of .DS_Store and ._ files

https://diigo.com/0nsozp for an annotated view of https://lists.apple.com/archives/applescript-users/2006/Jun/msg00180.html where Matt Deatherage (a former engineer at Apple) offers explanations. Also arnotify » On the origins of .DS_Store (2006-10-01).

Since I have seen loss of user data (document content) where ._ counterparts are prevented or lost, I agree that it's:

  • not acceptable to have things "vanish into the ether".

Purposes of ._ files

In addition to the purposes outlined in geekosaur's accepted answer, here are a few examples of how Apple and third party apps either use or require ._ in some situations …


File business during a copy by Finder

See my answer to a question on Stack Overflow.


NeoOffice use of deprecated codes

HFS type code NO%F without a creator code is:

  • used considerately, only where appropriate.

NeoOffice example 1

NeoOffice 3.2.1 Patch 5 save to JHFS+:

[macbookpro08-centrim:~] gjp22% xattr -l /Users/gjp22/Desktop/product\ of\ NeoOffice\ 3.2.1\ Patch\ 5.docx 
com.apple.FinderInfo:
00000000  4E 4F 25 46 00 00 00 00 00 00 00 00 00 00 00 00  |NO%F............|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020

NeoOffice example 2

NeoOffice 3.2.1 Patch 5 save to a USB flash drive with MS-DOS FAT32, cleaning by BlueHarvest:

2012-05-12 06:42:08.349 BlueHarvest[31146]: Deleted ._product of NeoOffice 3.2.1 Patch 5.docx in /Volumes/FAT32/example.

NeoOffice example 3

NeoOffice 3.2.1 Patch 5 save to a volume mounted by OS X with file system type webdav, not SharePoint, cleaning by BlueHarvest:

[macbookpro08-centrim:~] gjp22% mount | grep dav
https://www.box.net/dav/ on /Volumes/dav (webdav, nodev, noexec, nosuid, mounted by gjp22)
[macbookpro08-centrim:~] gjp22% xattr -l /Volumes/dav/product\ of\ NeoOffice\ 3.2.1\ Patch\ 5.docx 
[macbookpro08-centrim:~] gjp22% 
  • the save by NeoOffice to the webdav file system did not involve an extended attribute
  • BlueHarvest was not required.

Hint: where Microsoft Office fails with webdav to save to Microsoft SharePoint (see below), NeoOffice succeeds.


Microsoft use of deprecated codes

The most recent version of Office requires an HFS type code and HFS creator code when a format such as Microsoft Word (.docx) is chosen. So — it seems that when saving to a file system that does not support those values in a com.apple.FinderInfo extended attribute:

  • Microsoft Office can not save reliably without creating multiple ._ files.

Microsoft example 1

Word 2011 14.2.1 save to a volume mounted by OS X with file system type webdav, not SharePoint, cleaning by BlueHarvest:

May 11 18:32:49 macbookpro08 BlueHarvest[14649]: BlueHarvest started.
May 11 18:38:37 macbookpro08 BlueHarvest[14649]: Deleted ._Word Work File D_1.tmp in /Volumes/dav.
May 11 18:39:57 macbookpro08 BlueHarvest[14649]: Deleted ._Hello world, this is Microsoft.docx in /Volumes/dav.
May 11 18:42:28 macbookpro08 BlueHarvest[14649]: Deleted ._Hello world, this is Microsoft.docx in /Volumes/dav.

Microsoft example 2

Word 2011 14.2.2 (120421) saving example.docx in the same environment:

2012-05-12 08:01:07.692 BlueHarvest[41131]: Deleted ._Word Work File D_769960778.tmp in /Volumes/dav.

Microsoft example 3

Word 2011 14.2.2 (120421) saving another.docx in the same environment, quitting then reopening, editing then saving, editing then closing and saving:

2012-05-12 08:15:04.252 BlueHarvest[41131]: Deleted ._Word Work File D_.tmp in /Volumes/dav.
2012-05-12 08:18:48.735 BlueHarvest[41131]: Deleted ._another.docx in /Volumes/dav.
2012-05-12 08:21:12.658 BlueHarvest[41131]: Deleted ._Word Work File D_2.tmp in /Volumes/dav.

Hint: Microsoft Office 2011 fails to save to Microsoft SharePoint when the file system type is webdav because SharePoint does not support file names beginning with a dot . (period). See Ask Different answers to Is it possible to mount SharePoint as a volume in 10.6?


Type and creator codes: background, Apple Developer

Apple began encouraging third party developers away from type codes and creator codes more than a decade ago. In Appendix B of the File System Programming Guide, File Types and Creator Codes advises that the codes are:

generally deprecated, you may see them in legacy files and apps and in some places in the system.

1
19

These files are created by the operating system to speed up searches, store metadata (data used by the OS) about a folder preferences, etc. Windows and OS X both have these kinds of files. Following, is a description of these files pulled from http://annoying-file-be-gone.snack.ws/faq.html:

.DS_Store – The name of a file in the Apple OS X operating system for storing custom attributes of a folder such as the position of icons or the choice of a background image (Read more)

.Spotlight-V100 – This file holds information to speed up the 'Spotlight Search' feature. Deleting would simply force this information to be re-indexed if you performed another Spotlight Search for an item in this folder.

.apDisk – This file holds information about shared folders and can be safely removed as it will be automatically re-created if Apple needs it.

.VolumeIcon.icns – This file is used to store the icon of the volume (USB device) if the volume uses a custom icon and not the default icon. If you want the device to continue using this default icon, or if the folder/device you want to clean contains an application, you might want to keep this file in your system. As a side note, if you wanted to create a custom icon for your device you could create/download an .icns file and rename it .VolumeIcon.icns and place in your folder/device.

.fseventsd – This file is used as a buffer for the File System Events daemon. If you are using a program that is monitoring this folder/device, this file might be used to store temporary data.

.Trash & .Trashes – These folders are used to hold deleted items the same way that the 'Trash' icon from the dock works. If you don't need this feature on your folder/device, you can clean this folder to save space.

.TemporaryItems – This file is used by the OS to hold temporary data when files are being copied/moved/appended. If you are running any programs that are accessing the folder/device you want to clean, and you aren't copying or moving any files, then this file can simply hold old data for caching.

1
  • 5
    Good info, though ._ files remain a mystery. Nov 19, 2020 at 22:11
8

To minimise the presence of dot underscore files on non-HFS+ formatted drives, you can use the BlueHarvest preference pane.

1
  • 3
    BlueHarvest is an excellent product but some of the third party reviews are misleading. Test results show that creation is not prevented; that creation is allowed, and according to the user's preferences BlueHarvest may clean some of what's created. May 12, 2012 at 4:07
4

Use find . -name "._*" -type f -print to list out the files from local path

To remove these, with no warning or confirmation in bulk, use find . -name "._*" -type f -delete to delete all files.

2
  • Welcome to Ask Different! Although your answer shows how to remove the files, it does not answer the Why, What and How to avoid in the OP.
    – bjbk
    Apr 2, 2018 at 19:38
  • @bjbk This answer tells how to delete the files, just like Saeid Zebardast's highly-upvoted answer does. I agree neither one really addresses how to avoid them, nor why they appear.
    – LarsH
    Jun 8, 2018 at 16:07
3

It really is simple, NTFS (current Windows) FAT32 (Old Windows) have a very specific data structure for things like permissions, what program is assigned to open this file, creation date, modified date, tags, file comments, icon, and other metadata. You'll also notice that the same properties won't show in the other OS. (IE creation date may say it was in 1/1/1990 and other metadata is not accessible from the other OS. Whenever you are using both a machine writing from HFS to NTFS or FAT32 along with a machine writing native FAT32 or NTFS these . or ._ files along with DS store files will show up. It's show the OS's deal with the incompatibility factor of the varied elements above that aren't consistent. So you probably want to keep these files around if you are switching back and forth between the OS's to use these files. If you are only using one OS or the other ensure you have the media (hard drive, sd card, etc) formatted properly or have a driver which allows your OS to write to the drive format not native to your OS. (These are available for both OSX to allow it to write NTFS & FAT32 files using Native properties and for Windows 7 & 8 to write to HFS+ & EXFat (linux) drives using the native properties.) They aren't free, but if you do a lot of back and forth it cuts out the excess duplicate data cluttering the drive.

2

use rsync it does not create ._ files

1
0

You can delete them through FileZilla or similar files manager.

2
  • Not sure why this was downvoted since most of the upvoted answers don't even really give a solution. This is in my opinion the easiest solution... Since ._ and .DS_Store are Finder related files the obvious solution is to avoid finder. Personally I prefer using Transmit, but Filezilla is a great free alternative. May 25, 2016 at 20:42
  • 3
    I didn't downvote but it's an undesirable suggestion and misses the intention of the question which is asking for prevention rather than cure. Who wants to spend half their time deleting these files that keep getting generated? Q: "What do I do about our city's littering problem?" A: "Pick it up and put it in the bin, duh." Jun 30, 2016 at 3:27
0

Yes, some of us have a use for both Macs and windows machines, and I used to use that method. And if you have a USB with a bunch of .jpgs that you want to play as a slide show, you have to get rid of those pesky ._ files to do it. After much searching, I found a way to use my mac to remove the ._ files:

using Terminal:

  • ls -a will list all files, including the one starting with ._
  • to remove just one file from the directory: rm -rf ._whateveryourfilenameis.jpg
  • to remove all ._ files: rm -rf ._*
  • to remove unwanted directories including .Trashes: rm -r .Trashes*

Cleaned my USB right up for use as a TV input

0

I've created some tools to remove these properly:

https://github.com/drazulay/turdmaster

💩 turdmaster

Functions to delete Mac OSX filesystem turds

Turds?

Turds are filesystem artifacts on Mac OSX that start with ._, they are created by the OS to hold extra filesystem attributes supported by HFS+.

When moving to linux or windows, or deploying files to a server, these turds are of no value.

is_turd

Checks whether a file is a turd, exits with status 0 if true or 1 if false.

It does this not by checking whether the file extension starts with ._ but by checking if the file header bytes translate to the hexadecimal string 00051607000200004d6163204f532058.

dump_turd

Checks whether a file is a turd and removes it if so.

dump_turds

Searches a path for turds and removes them.

Just put them in your $HOME/.bin folder or put them in ${HOME}/.bin/turdmaster - make sure the one you use is added to $PATH in your shell's rc file.

-2

I have been using the following method for easy .* prefix file elimination on flash drives: Remove flash drive from Apple computer, insert into a Windows machine, search the flash drive for ".*.*", then when the search displays the files with the ._ prefix, delete them. I never delete .Trashes or .DS Store files. So far no issues. I hope I am not causing a future problem for myself.

1
  • 1
    Manual deletion? Ownership of a Windows computer when you're a Mac user? I know you're just documenting what works for you but I can't imagine anyone following your method. Jun 30, 2016 at 3:30
-3

Be careful when deleting ._ related to Git, Visual Studio, and Xcode! I have an app with a lot of .mov and images and these "._" files showed up to be committed. I deleted them via Visual Studio Team Explorer's changes and somehow that project folder bloated from around 500MB to 40GB without adding files...still not sure what happened exactly, but I'm guessing it was related to deleting those files so every commit it cached each .mov and image multiple times before I caught on. I saw each .mov and .png repeated 20-30 times when in Finder > All Files.

Just add "._*" to your .gitignore file and they won't show up as a changed file when using TFS for you iOS Xcode project.

You must log in to answer this question.

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