
How to Install or Update Python on Kali Linux
June 18, 2025
What Is Nuclei and Why Bug Hunters Love It
June 20, 2025How to Archive Files with tar Command in Linux
The tar
command is one of the most versatile tools in Linux for archiving files and directories. It allows you to package up multiple files into a single file, which makes storage, transfers, and backups easier to manage.
1. Basic Syntax
tar [options] [archive_name.tar] [files...]
2. Create an Archive
tar -cvf archive.tar file1.txt file2.txt
Options explained:
-c
: Create a new archive-v
: Verbose output-f
: Use archive file name
3. Archive a Directory
tar -cvf backup.tar /path/to/directory
This will recursively archive the entire directory including all subfolders and files.
4. Create a Compressed Archive
Using gzip compression:
tar -czvf archive.tar.gz folder/
Using bzip2 compression:
tar -cjvf archive.tar.bz2 folder/
Using xz compression:
tar -cJvf archive.tar.xz folder/
5. View Archive Contents
tar -tvf archive.tar
This will list all files stored inside the archive without extracting them.
6. Extract an Archive
tar -xvf archive.tar
To extract into a specific directory:
tar -xvf archive.tar -C /path/to/extract
7. Tips and Best Practices
- Use
-z
,-j
, or-J
to reduce archive size. - Always inspect with
-t
before extracting unknown tar files. - Combine
-v
with other flags to see what’s happening during operations.
That’s it — now you know how to archive, compress, extract, and inspect tar files on Linux like a pro. The tar
command is a must-have in your toolbox whether you’re doing backups, transfers, or automation scripts.