On Linux Mint, use the tar command in the Terminal to create, inspect, and extract archive files. For example, tar -czf backup.tar.gz Documents/ creates a compressed archive of the Documents folder, while tar -xzf backup.tar.gz extracts it into the current directory.
What tar Does on Linux Mint
tar is a standard command-line tool for bundling files and directories into one archive. Its name comes from “tape archive,” reflecting its history in storing groups of files on tape. Despite that origin, it is widely used for everyday backups, source-code packages, and transferring collections of files.
A tar archive can preserve directory structure and file metadata such as permissions and modification times. By itself, tar bundles files but does not compress them. Compression is usually added with an option such as gzip or xz, producing familiar extensions like .tar.gz or .tar.xz.
Linux Mint provides a graphical archive manager for common archive tasks, but Terminal commands are useful for repeatable jobs, remote systems, and large directory trees. The examples below work in Mint’s Terminal; run them from the directory containing the files unless an example specifies otherwise.
Understanding tar Options and Archive Names
Many tar commands combine short options immediately after a hyphen. For example, -czf means create an archive, compress it with gzip, and write it to the filename that follows. The letters are options, not part of the archive name:
c: create a new archive.x: extract an archive.t: list the archive’s contents.f: use the following argument as the archive filename.z: filter through gzip compression.J: filter through xz compression.v: show filenames as tar processes them.
The placement of f matters: put the archive filename after the option letters. For example, in tar -czf backup.tar.gz Documents/, backup.tar.gz is the archive, and Documents/ is the folder being added. The v option is optional; omit it for less screen output.
Create an Archive or Backup
To bundle a folder without compression, run:
tar -cf documents.tar Documents/
For a smaller gzip-compressed archive, use:
tar -czf documents.tar.gz Documents/
To use xz compression, which may take longer but can create a smaller file, use:
tar -cJf documents.tar.xz Documents/
These commands include the named folder and its contents. To archive several paths, list them after the archive filename, for example:
tar -czf work.tar.gz report.odt Projects/ notes.txt
To save a backup outside the current directory, provide a destination path for the archive, such as tar -czf /home/ sam/backup.tar.gz Documents/ only if that path is correct for your system. A safer pattern is to use your home-directory shortcut: tar -czf ~/documents-backup.tar.gz ~/Documents/. The archive stores paths relative to the paths you provide; for cleaner archive contents, change to the parent directory first and archive the folder by its relative name.
A tar archive is not automatically a complete system backup. It does not decide what should be backed up, where the backup should be stored, or whether the result can be restored. Keep important backups on a separate drive or other storage, and periodically test that you can list and extract them.
List and Extract Archive Contents
Before extracting an unfamiliar archive, list its contents:
tar -tzf backup.tar.gz
For an uncompressed archive, omit z: tar -tf files.tar. For an xz archive, use tar -tJf files.tar.xz. Listing first can reveal the folder structure and help you avoid extracting files into an unexpected location.
To extract a gzip-compressed archive into the current directory, run:
tar -xzf backup.tar.gz
To extract it into a specific directory, use -C followed by the destination:
mkdir -p ~/restoretar -xzf backup.tar.gz -C ~/restore
The destination must exist before extraction. Use -xJf for an xz archive or -xf for an uncompressed tar file. Extraction can overwrite files with matching names, so inspect an archive and choose a suitable destination, especially when it came from an unknown source.
Tar Compared with ZIP and the Archive Manager
Tar is a good choice when you want a single bundle that preserves Linux file details, or when following instructions that specify a tar archive. ZIP is often convenient when sharing files with people using Windows or other platforms, since it is broadly supported by graphical tools. A ZIP file commonly bundles and compresses its contents in one format; tar usually relies on a separate compression method when a smaller archive is needed.
On Linux Mint, you can also open many archives in the graphical archive manager by double-clicking them in the file manager. This is approachable for occasional work and lets you browse or extract files without memorizing options. Terminal tar is particularly handy for scripting and precise control. Neither method is inherently a replacement for a backup plan: the important questions are what is included, where the archive is kept, and whether it can be restored.
Common Problems and Safe Practices
- “Cannot open” or “No such file”: Check that the archive name and path are correct. Use
lsto inspect the current directory, or provide a full path. - Wrong compression option: Match the option to the format:
zfor gzip,Jfor xz, and no compression flag for a plain tar archive. The extension is a clue, but not proof of the format. - Unexpected extraction location: Run
tar -tf archive.tar.gzfirst and extract with-Cinto a dedicated folder. - Permission errors: Choose a directory you own. Do not add
sudoautomatically; elevated privileges can create root-owned files or overwrite important system files. - Archive is larger than expected: Tar alone does not compress. Use
-zor-Jwhen you want compression.
For archives from untrusted sources, do not extract them blindly into your home directory. Review the listing, avoid running files merely because they were archived, and use a temporary destination if you are unsure. Extraction is not a security check, and archive contents can include executable files or paths intended to affect existing files.
Frequently Asked Questions
How do I create a tar.gz file in Linux Mint?
Run tar -czf archive.tar.gz folder/, replacing the archive name and folder with your choices. Add v, as in -czvf, if you want tar to print the filenames it processes.
How do I extract a tar.gz file in Linux Mint?
Use tar -xzf archive.tar.gz to extract it into the current directory. To choose a destination, create that directory and add -C /path/to/directory.
What is the difference between .tar and .tar.gz?
A .tar file bundles files without compression. A .tar.gz file is a tar archive compressed with gzip. Both can be handled with tar, but the gzip version uses the z option.
How do I see what is inside a tar file without extracting it?
Use tar -tf archive.tar for an uncompressed archive or tar -tzf archive.tar.gz for gzip compression. For xz compression, use tar -tJf archive.tar.xz.
Does Linux Mint have a graphical alternative to tar?
Yes. Open many archive files with Mint’s archive manager from the file manager to browse or extract them. The Terminal remains useful for creating repeatable commands and working with archives in scripts.