Does tar -x Extract to Current Directory or Does it Extract to the Source of the Archive?
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.
Related videos on Youtube
haziz
Updated on September 18, 2022Comments
-
haziz over 1 year
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 thebackup.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/
?-
Admin over 11 years
tar -tf ~/backup.tar.bz2
should tell you what you want to know. Paths are relative.
-
-
Gert van den Berg over 11 yearsSolaris's default tar is on that does not do the conversion... Dangerous extracting things without a -t first... Things tend to get overwritten.
-
Alexander Mills about 6 yearshow can we extract to a new path instead of the absolute path of the original file?