To recover an .tar.xz archive from an external desktop drive, decompress it with tar -xJf (or extract the .xz layer first with xz -dk then untar), and if the file is damaged, use xz --single-stream --decompress to salvage the readable part before untarring. The short answer: copy the archive to your internal disk first, verify its integrity, then extract with the right flag — never extract in place on a failing drive.
This guide walks through the safe order of operations, the exact commands, and what to do when the archive refuses to decompress. Menu labels and command flags can differ slightly by version and distribution, so check man tar and man xz on your own system if a flag is rejected.
What You'll Need
- The external drive containing the
.tar.xzfile, connected by USB or Thunderbolt and mounted read-only if possible. - A computer with a terminal: Linux, macOS, or Windows with WSL. On Windows, 7-Zip can open
.tar.xzin two passes (xz, then tar) if you prefer a GUI. - Free space on your internal drive at least twice the size of the archive — one copy for the archive, one for the extracted files.
- The
tarandxzutilities (installed by default on most Linux distributions and macOS; on Debian/Ubuntu,sudo apt install xz-utilsif missing). - Optionally, a second healthy drive to hold a backup copy before you touch anything.
Step-by-Step
- Stop writing to the external drive. Do not delete, rename, or move anything on it. If the drive is making clicking or grinding noises, unplug it and treat the data as at-risk; every write shortens its life.
- Identify the device and mount point. Run
lsblk(Linux) ordiskutil list(macOS) to confirm which device is the external drive. Note the mount path, for example/media/you/Backupor/Volumes/Backup. - Copy the archive to your internal disk. Use
cp /media/you/Backup/archive.tar.xz ~/recovery/. Copying first means a failing drive only has to be read once, and a bad sector will not corrupt the extraction mid-stream. - Verify the copy. Compare checksums:
sha256sum /media/you/Backup/archive.tar.xz ~/recovery/archive.tar.xz. If they match, the copy is intact. If they differ, re-copy; if it fails again, the source is damaged. - Test the archive's integrity before extracting. Run
xz -t ~/recovery/archive.tar.xz. A silent exit means the compressed stream is valid. Any error means the file is truncated or corrupted — skip to Troubleshooting before extracting. - Create an empty destination folder.
mkdir -p ~/recovery/extracted. Extracting into a dedicated folder prevents tar from scattering files across your home directory. - Extract with the correct flag. From inside the destination folder, run
tar -xJf ~/recovery/archive.tar.xz. The-xextracts,-Jfilters through xz, and-fnames the file. Add-vto list files as they unpack. - If you prefer two passes, run
xz -dk archive.tar.xzto producearchive.tar, thentar -xf archive.tar. This is useful when you want to inspect the tarball or when tar's built-in xz support is missing. - Check permissions and ownership. If files extract with wrong owners, re-run as your user (not root) or use
tar --no-same-owner -xJfto strip stored ownership. Never extract an untrusted archive as root. - Confirm the contents. List the archive without extracting first:
tar -tJf archive.tar.xz | head -50. Compare the count to the extracted files withfind ~/recovery/extracted -type f | wc -l. - Safely eject the external drive. Use
udisksctl unmount -b /dev/sdX1ordiskutil unmountbefore unplugging, so cached writes are flushed.
Common Mistakes
- Extracting directly on the external drive. This doubles the read/write load on a device that may already be failing and can overwrite deleted-but-recoverable data.
- Using
-zinstead of-J.-zis for gzip (.tar.gz); xz needs-Jor the two-pass method. - Forgetting the
-fflag. Without it, tar reads from standard input and hangs waiting for data. - Running as root. Extracting an archive you did not create as root can overwrite system files if the archive contains absolute paths.
- Ignoring
xz -tfailures. A failed integrity test means extraction will produce partial or corrupt output; deal with the corruption first. - Unplugging without unmounting. Pulling a drive mid-write can corrupt the filesystem and make recovery harder.
Tips
- Keep the original archive untouched until you have verified the extracted files; it is your fallback.
- Use
tar -tJfto preview contents before extracting — it is fast and non-destructive. - If the archive is huge, extract to a drive with plenty of headroom; running out of space mid-extraction leaves a partial tree.
- Store checksums alongside archives in future so integrity checks are one command.
- For long-term storage, keep two copies on different media; a single external drive is not a backup.
Troubleshooting
If xz -t reports corruption: the compressed stream is damaged. Try xz --single-stream --decompress archive.tar.xz to salvage the first readable stream, then untar whatever it produces. If the file is truncated, xz may still decompress up to the break point; the resulting tar will be incomplete but often usable for the files that did unpack.
If tar says "unexpected EOF": the archive is incomplete. Re-copy from the source if possible; otherwise extract what you can and accept partial recovery.
If the drive is not detected: try another cable and port, check dmesg for errors, and test the drive on a second computer. If it clicks or is not seen at all, stop and consider professional data recovery rather than repeated power cycles.
If extraction stops with "Cannot open: No space left on device": free space or extract to a larger drive, then re-run.
If files extract but are unreadable: the archive may have stored them corrupted. Compare checksums against any manifest, and re-copy the source archive if a second copy exists.
Frequently Asked Questions
Can I extract a .tar.xz directly from the external drive?
You can, but do not. Copy it to your internal disk first so a failing drive is read only once and a bad sector cannot corrupt the extraction.
What is the difference between -J and -z in tar?
-J filters through xz, which is what .tar.xz needs. -z filters through gzip and is for .tar.gz files.
Does Windows open .tar.xz natively?
Modern Windows can open tar archives, but xz support varies by version. 7-Zip handles .tar.xz reliably in two passes: open the xz layer, then the tar inside.
Can I recover files if the archive is partially corrupted?
Often yes. xz --single-stream and extracting up to the error point can recover the readable portion; files after the corruption may be lost.
Is it safe to extract an archive as root?
No. Extract as your normal user; stored ownership and absolute paths in an untrusted archive can overwrite system files.