This tutorial shows how to mount a TAR archive file (.tar.gz
, .tgz
, .tar.bz2
, .tar
, etc.) as a directory on Ubuntu so that you can access the contents without first unpacking them to disk. When you're done viewing (or even modifying) the contents, you can simply unmount the TAR file. Any changes you make will be applied to the TAR file itself.
If you're using an Ubuntu laptop or desktop, you can press Ctrl + Alt + T
on your keyboard to open a new terminal window. If you're using a remote Ubuntu server, you can connect using SSH to open a new terminal session.
archivemount
Make sure you have archivemount
installed:
sudo apt install -y archivemount
You can mount the TAR file at any directory (called the mount point), as long as you have write permission for the directory. Here, we'll mount it at /tmp/myfiles
:
mkdir /tmp/myfiles
To mount a TAR file named myfiles.tar.gz
at our mount point from the previous step:
archivemount myfiles.tar.gz /tmp/myfiles
Now you can access the contents of your TAR file by going to the mount point directory:
1 2 | cd /tmp/myfiles
ls
|
When you're done with the contents, you can simply unmount:
cd && umount /tmp/myfiles
Note that the command to unmount is umount
(no n
right after the u
), not "unmount."
The cd &&
part of the command above moves you to your home directory before unmounting, so that you're not inside the mount point after it is unmounted.
Optionally after you unmount, you can delete your mount point:
rmdir /tmp/myfiles
You've just accessed the contents of a TAR file without first unpacking them to disk.