tar, Leopard, and those evil, nasty resource forks

I’m posting this so that others don’t have to endure the frustration I just did searching for a solution.

The Problem

tar -cvzf output_file.tgz input_dir

This includes .DS_Store files and resource forks (files beginning with ._).

The Solution

Apparently there is an environment variable that tricks OS X into not including these resource forks: COPY_EXTENDED_ATTRIBUTES_DISABLE. However, this was deprecated in Leopard. The new solution is COPYFILE_DISABLE. The .DS_Store files can be excluded with tar’s --exclude option. Here are the final commands:

export COPYFILE_DISABLE=true
tar -cvz --exclude="*DS_Store" -f output_file.tgz input_dir

I hope I save people trouble. :)