Linux Tar Command: Complete Guide & Examples

Tar is a commonly used file packaging and compression tool in the Linux system. It allows multiple files or directories to be packaged into a single file and can also compress the packaged files. Here is a detailed tutorial on the tar packaging command.

  1. Pack up files or directories:
  2. Create a tar archive with the specified file or directory.
  3. For example, to create a file named backup.tar containing all files and directories in the current directory:
  4. Create a backup file called “backup.tar” containing all files in the current directory.
  5. View the contents of the packaged file:
  6. List the contents of the tar file using the command tar -tvf .
  7. For example, to view the contents of the backup.tar file:
  8. List the contents of the backup.tar file
  9. Unzip the compressed file.
  10. extract the files from the compressed file named
  11. For example, to decompress the backup.tar file:
  12. Extract the contents of the backup.tar file.
  13. Package and compress using gzip:
  14. Create a compressed file named containing the specified files or directories.
  15. For example, to compress all files and directories in the current directory into a tar.gz file named backup.tar.gz:
  16. Create a compressed backup file called backup.tar.gz including all files and folders.
  17. Extract and decompress tar.gz file.
  18. Unpack the file by using the command: tar -xzvf
  19. For example, to unpack and decompress the backup.tar.gz file:
  20. Extract the contents of backup.tar.gz
  21. Package and compress with bzip2:
  22. Create a .tar.bz2 file with the specified name that includes the specified files or directories.
  23. For example, to pack all files and directories in the current directory and compress them with bzip2, creating a file named backup.tar.bz2:
  24. Create a compressed tar archive called backup.tar.bz2 of all files in the current directory.
  25. Unzip and decompress the tar.bz2 file.
  26. Unpack the compressed file by running the following command: tar -xjvf
  27. For example, to decompress and extract the backup.tar.bz2 file:
  28. Extract the contents of the backup.tar.bz2 file.

Here is a detailed tutorial on the tar packaging command. When using the tar command, please choose the appropriate options and parameters according to your actual needs.

bannerAds