Computer Science Atlas
Step-By-Step

Ubuntu: Mount a TAR File as a Directory

February 13, 2021
 
Table of Contents

View/Edit Contents Without Unpacking

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.

Step 1. Open a Terminal Session

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.

Step 2. Install archivemount

Make sure you have archivemount installed:

bash
sudo apt install -y archivemount
sudo apt install -y archivemount

Step 3. Create Mount Point Directory

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:

bash
mkdir /tmp/myfiles
mkdir /tmp/myfiles

Step 4. Mount the TAR file

To mount a TAR file named myfiles.tar.gz at our mount point from the previous step:

bash
archivemount myfiles.tar.gz /tmp/myfiles
archivemount myfiles.tar.gz /tmp/myfiles

Step 5. View or Edit Files

Now you can access the contents of your TAR file by going to the mount point directory:

bash
cd /tmp/myfiles
ls
1
2
cd /tmp/myfiles
ls

Step 6. Unmount

When you're done with the contents, you can simply unmount:

bash
cd && umount /tmp/myfiles
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:

bash
rmdir /tmp/myfiles
rmdir /tmp/myfiles

Congratulations!

You've just accessed the contents of a TAR file without first unpacking them to disk.