Prevent Mac Finder From Creating Dot Underscore ._ Files on Linux Samba Shares

The macOS uses a type of file metadata called "extended attributes" to store additional information about a file besides its basic info (name, last modified date, etc). On a Macintosh, this metadata is stored directly in the filesystem so the user generally doesn't notice it.

However, when connecting to network file shares that do not support extended attributes, such as Samba on Linux, the Mac instead creates files prefixed with a dot-underscore ._ to hold that metadata. Each "actual" file will have an accompanying dot-underscore file created. If you were to perform a directory listing, you would see:

._file1.txt._file2.pdf._file3.xlsxfile1.txtfile2.pdffile3.xlsx

This becomes incredibly annoying when using non-Mac computers to access the file share.

A lot of the time, you don't really need this metadata, and can just throw it away if you want. Luckily, it's very straightforward to prevent these files from being created on your Linux Samba shares.

Open your /etc/samba/smb.conf file and scroll to bottom of the [global] section. Add the following lines:

# Delete garbage Apple filesveto files = /._*/delete veto files = yes

The veto files setting is a list of regular expressions, separated by slashes /, that the Samba daemon will prevent from being created. ._* indicates that any file starting with a dot-underscore is blocked.

Along the same lines, the .DS_Store file is also used by the macOS to retain folder information in the Finder (column layout, etc). If you don't care about this info and want these files blocked as well, change the veto files setting to:

veto files = /.DS_Store/._*/

Restart the Samba service with the following command and you'll see this take effect with any new files or file updates.

sudo service smbd restart