Does tar -x Extract to Current Directory or Does it Extract to the Source of the Archive?

6,381

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:
6,381

Related videos on Youtube

haziz
Author by

haziz

Updated on September 18, 2022

Comments

  • haziz
    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 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 /?

    • Admin
      Admin over 11 years
      tar -tf ~/backup.tar.bz2 should tell you what you want to know. Paths are relative.
  • Gert van den Berg
    Gert van den Berg over 11 years
    Solaris'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
    Alexander Mills about 6 years
    how can we extract to a new path instead of the absolute path of the original file?