1

I had a directory of files that I compressed using:

tar -cvJf my_directory.xz my_directory

Now I've gone to decompress it using:

xz -dv my_directory.xz my_directory

and the resulting file is simply my_directory. It has no extension and it's not a directory, but the size corresponds exactly with what the original directory should be in its decompressed state.

-rw-rw-r-- 1 user computer 1.1G Jun  8 12:16 my_directory

What did I do wrong, and is there a way to remedy this if I no longer have access to the original uncompressed directory?

lusk
  • 113
  • 5
  • I'm realizing now that most likely the first mistake I made was in compressing a *directory* as only a `.xz` file instead of a tarball (`.tar.xz`). – lusk Jun 13 '23 at 13:57
  • 1
    I’m voting to close this question because OP admitted he made simple mistake (in comment) – Joep van Steen Jun 13 '23 at 14:12
  • 1
    Why are you using `xz` to decompress it now? Did you try `tar -x`? – Destroy666 Jun 13 '23 at 14:29
  • Honest answer? I forgot that I used `tar` in the first place. But that leads to another question—if you use `tar` to compress a tarball, but don't include `.tar` in the file extension of the desired filename, does it still compress as a tarball? – lusk Jun 13 '23 at 14:30
  • What do you mean "you forgot"? You listed commands above. Not that it'll help likely, I'm just not following. I wouldn't close this BTW as I'm curious if it's still solvable. – Destroy666 Jun 13 '23 at 14:41
  • I decompressed the `.xz` file using `xz` (and not `tar`) because I forgot that I originally compressed it using `tar` (which I did weeks ago). I had already decompressed it prior to writing. – lusk Jun 13 '23 at 14:45
  • 1
    For future reference: `file` is the right starting point when dealing with files of unknown format. `file my_directory` would probably tell you it's a tar archive. – Kamil Maciorowski Jun 13 '23 at 16:00

2 Answers2

1

Another solution would be to just revert the actions with:

  1. xz -zv my_directory my_directory.xz (-z compress flag instead of -d decompress)
  2. tar -xvJf my_directory.xz (-x extract flag instead of -c create)

Which is something to always keep in mind as a possibility in terms of reversible operations such as compression.

What happened wrong here and why did tar -xf my_directory work?

Basically, xz -d simply decompressed the .tar.xz archive that you made, but still left it as a tarball .tar archive called my_directory without the extension as instructed.

You could have also renamed the file to anything.tar and then it would open correctly in the GUI.

Destroy666
  • 5,299
  • 7
  • 16
  • 35
0

It turns out simply running tar -xf my_directory on the "decompressed file" successfully decompresses it into the original my_directory/ directory.

lusk
  • 113
  • 5