Working With Tar Compressed Archives in Linux
In Linux, the tar
command is commonly used for archiving and extracting files and directories. Tar archives can be compressed to save space using various compression algorithms like gzip (*.tar.gz
) or bzip2 (*.tar.bz2
). This guide will cover how to create, extract, and work with tar compressed archives in Linux.
Compressing Files and Directories with Tar
1. Create a Tar Archive
To create a tar archive of a folder, use the tar -cvpf
command:
|
|
2. Create a Gzipped Tar Archive
To create a gzipped tar archive (commonly referred to as a .tar.gz
file), use the -z
option along with tar -czvpf
:
|
|
3. Create a Gzipped Tar Archive Without Parent Directory
To create a gzipped tar archive without including the parent directory in the archive, use the -C
option:
|
|
Extracting Tar Archives
1. Extract a Tar Archive
To extract the contents of a tar archive, use the tar -xvpf
command:
|
|
2. Extract a Gzipped Tar Archive
To extract the contents of a gzipped tar archive, use tar -xzvpf
:
|
|
3. Extract with Specific Folder
To extract the contents of a gzipped tar archive into a specific folder, use the -C
option:
|
|
Listing Contents of a Tar Archive
To list the contents of a tar archive, use the tar -tvf
command:
|
|
These commands should cover most of your needs for creating, extracting, and listing the contents of tar compressed archives in Linux. Make sure to replace file.tar
, folderToCompress
, folderPath
, selectedDir
, and other placeholders with your actual file and directory names as needed.