How to avoid clobbering files when creating a tar archive

Posted by Andrew Grimm on Stack Overflow See other posts from Stack Overflow or by Andrew Grimm
Published on 2009-07-14T01:09:35Z Indexed on 2010/03/30 4:03 UTC
Read the original article Hit count: 457

Filed under:
|
|

This question notes that it is possible to overwrite files when creating a tar archive, and I'm trying to see how to avoid that situation.

Normally, I'd use file roller, but the version installed is playing up a bit (using 1.1 Gb of memory), and I'm not the system administrator.

I looked at --confirmation and --interactive, but that only asks me if I want to add file x to the archive, not whether I want to overwrite an existing file. For example,

tar --interactive -czvf innocent_text_file.txt foo*

Will ask me about each file, but is perfectly happy to overwrite innocent_text_file.txt

Is there any switch that acts like -i for cp?

Note I am asking about creating an archive, not extracting an archive.

Clarification What I'm worried about is accidentally doing something like this

tar -czvf * #Don't do this!

which would overwrite the first file listed in the glob. To avoid it, I want tar to complain if the first file mentioned already exists, like

cp -i * #Don't do this!

would check if it would cause you to overwrite an existing file.

© Stack Overflow or respective owner

Related posts about tar

Related posts about confirm