1

I'm looking how to prevent tar from saving or creating .AppleDouble shadow files and preferably do it in an automated manner. There are a few questions asking why this happens, but I want a solution that helps me prevent this in practice.

What do I need to do using terminal when I tar a directory to prevent these files from being generated?

The duplicate (linked above) as it has been pointed out shows a whole bunch of lines which I do not understand. I'm pretty new to working with Terminal, so that is probably the reason why I don't grasp it.

$ xattr -l file.jpg
com.apple.quarantine: 0002;50d20c48;Tweetbot;
$ tar -cf 1.tar file.jpg 
$ tar -tf 1.tar 
./._file.jpg
file.jpg
$ COPYFILE_DISABLE=1 tar -cf 2.tar file.jpg 
$ tar -tf 2.tar 
file.jpg

I just cannot imagine that every time I want to tar a directory I need this bunch only to achieve not getting duplicates.

Regarding the solutions given below in the comments, does it mean that every time I want to tar something I have to use that whole line? Or is there a way to tell the system to set this as the default behaviour when tarring files?

  • Set COPYFILE_DISABLE to some value, like COPYFILE_DISABLE=1 tar -cf directory.tar directory. – Lri Jun 19 '13 at 3:58
  • Thanks @LauriRanta I saw that question, but did not understand the answer. So what you're saying is that every time I tar a folder, I will have to add the COPYFILE_DISABLE=1 ? Isn't there a way to do that automatically each time I tar files/directories? – user51504 Jun 19 '13 at 7:51
  • I use an alias like alias tarc="COPYFILE_DISABLE=1 tar --exclude '\\.DS_Store' -c". alias tar="COPYFILE_DISABLE=1 tar" would also make tar -x keep ._ files. – Lri Jun 19 '13 at 20:29
  • The other question might ask why but the answer on it does answer how to stop the odd files so the question/answer is a duplicate not the text now says "This question already has an answer here:" – Mark Jun 20 '13 at 1:18
  • Well, with all due respect, but the answer that @LauriRanta gave about making an alias actually does answer my question and looks - imho - a whole lot different from the "duplicate", which says nothing on how to automate this. – user51504 Jun 20 '13 at 1:25
1

@LauriRanta answered the question by giving two solutions.

The first solution is to use COPYFILE_DISABLE=1 tar -cf directory.tar directory each time you want to tar a directory without the hidden files.

Her 2nd solution however - and also the one I was looking for - shows how to automate the whole lot by using an alias. If you don't know what an alias is (I didn't) there is a great tutorial available here that shows how to create a temporary alias (only valid for current session) and a permanent alias (stays valid even after turning your Mac off).

I used Lauri's suggestion with a few additions to create a permanent alias:

alias tarc="COPYFILE_DISABLE=1 tar --exclude '\\.DS_Store' -zcf"

so next time I want to tar a directory without overhead I only have to write tarc chosen-gzipped-tar-filename.tgz name-of-directory-i-want-to-tar/ and beam it up to my webhost.

Thanks for all comments and input!

You must log in to answer this question.