Bash tar
- An archiving utility
Using the tar
Command
The tar
command is used to create, maintain, modify, and extract files from an archive file.
TAR Options Overview
Here are some common options you can use with the tar
command:
-c
- Create a new archive-x
- Extract files from an archive-t
- List the contents of an archive-z
- Filter the archive through gzip-v
- Verbosely list files processed-f
- Specify the filename of the archive
Option: -c (Create)
The -c
option creates a new archive with the specified files.
Example: Create Archive
tar -cvf archive.tar file1 file2
file1
file2
Option: -x (Extract)
The -x
option extracts files from an archive.
Example: Extract Files
tar -xvf archive.tar
file1
file2
Option: -t (List)
The -t
option lists the contents of an archive without extracting them.
Example: List Archive Contents
tar -tvf archive.tar
-rw-r--r-- user/user 1234 2025-04-10 12:00 file1
-rw-r--r-- user/user 5678 2025-04-10 12:00 file2
Option: -z (Gzip)
The -z
option filters the archive through gzip, compressing or decompressing it.
Example: Gzip Compression
tar -czvf archive.tar.gz file1 file2
file1
file2
Option: -f (File)
The -f
option specifies the filename of the archive to create or operate on. It should be used as the last option before the archive name.
Example: Specify Archive Filename
tar -cvf archive.tar file1 file2
file1
file2
Option: -v (Verbose)
The -v
option provides verbose output, listing files as they are processed.
Example: Verbose Output
tar -xvf archive.tar
file1
file2