Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Does tar -x by default just extract to the current directory or does it try to reproduce the original directory structure including overwriting the original source? I know I can specify a folder to extract to by using -C directory/ but I am asking about it's default behavior.

So if I used tar -cvpjf ~/backup.tar.bz2 / to make a backup of my root directory and I then extract the backup.tar.bz2 (assuming I had root privileges) from within my home directory would it recreate / in my home directory or would it actually try to overwrite /?

share|improve this question
1  
tar -tf ~/backup.tar.bz2 should tell you what you want to know. Paths are relative. –  jordanm Dec 2 '12 at 19:54

1 Answer 1

up vote 7 down vote accepted

Historically, if the paths in the archive were absolute, then they were extracted at the absolute location referred to in the archive. Some tar implementations offer an option to convert those to relative (/foo/bar becomes ./foo/bar) and some like GNU tar even make it the default.

So, in short, it depends on your tar implementation. You should look at the manual for your tar on your own system.

share|improve this answer
    
Solaris's default tar is on that does not do the conversion... Dangerous extracting things without a -t first... Things tend to get overwritten. –  Gert van den Berg Dec 3 '12 at 6:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.