Getting Started with tar
Understanding tar Basics
The tar command in Linux is a powerful tool used for creating, manipulating, and extracting archive files, commonly known as "tarballs". These archives can contain multiple files and directories, making them useful for backup, distribution, and storage purposes.
Common tar Commands
The most common tar commands are:
tar -cf archive.tar files/: Create a new tar archive named archive.tar containing the specified files and directories.
tar -xf archive.tar: Extract the contents of the archive.tar file to the current directory.
tar -tf archive.tar: List the contents of the archive.tar file without extracting it.
Creating tar Archives
To create a new tar archive, use the following command:
tar -cf archive.tar file1.txt file2.txt directory/
This will create a new archive file named archive.tar containing file1.txt, file2.txt, and the directory/ folder.
To extract the contents of a tar archive, use the following command:
tar -xf archive.tar
This will extract all the files and directories from the archive.tar file to the current directory.
Listing tar Archive Contents
To list the contents of a tar archive without extracting it, use the following command:
tar -tf archive.tar
This will display a list of all the files and directories contained within the archive.tar file.