Stop tar from copying Mac OS X resource fork files
Resource fork files on Mac OS X isn’t something new. It’s been there way back from the old Mac operating system versions. These are files that starts its name with a ‘._’ followed by the original name of the file. It becomes a nuisance dealing with them when you have to copy files from a Mac to some other operating system like Ubuntu or Windows.
The problem becomes particularly evident when you want to backup files using the tar program on Mac OS X and you find out that using the exclude option doesn’t want to follow your request to stop copying those resource fork files.
Don’t give up, ‘coz there’s a solution to that. I learned it the hard way so I decided to post the solution here so I won’t forget about it and so that others may find it. As it turns out, the solution is quite simple but depends on the version of the Mac OS X you are currently using. Both solutions require you to set an environment variable on your Mac.
For Mac OS X Tiger users, you need to set the COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable to true. Just execute the command below on a Mac OS X terminal window. You can do this automatically by adding the command to your .bash_profile file.
Mac OS X Leopard and new versions use a different environment variable. Just set the COPYFILE_DISABLE environment variable to true by executing the command below. Of course you can also make it automatic by inserting the command into .bash_profile.
After having done that, try using tar again and like magic it now prevents tar from backing up those pesky resource fork files. Another type of file that you might also want to exclude from copying is the .DS_Store files. This time you can just use the –exclude option of tar for that. Example:
tar -c –exclude ‘.DS_Store’ -f backup.tar directory-to-backup
Hope this tip helps.
Gerry Ilagan is into mobile apps and WordPress development at @speeqs. He loves to write about electronics, the Internet of Things, mobile phones, and #crazyideas.