

Adding files to existing tar archive file
/7-zip-tar-windows-10-d1ae3c8f965a45eeab7da6131152bd51.png)
Tar -cvfj file_2 /home/net2_admin/Downloads Though it takes more time to compress, the bz2 enabled compression yields a more compressed file when compared to the usual gzip in terms of size.This also applies to decompression with bz2.įor instance in order to create a bz2 enabled compression on a directory, execute the command below : It is possible to compress files to even smaller sizes using the bz2 feature. Tar -czvf archived_ /home/flder –exclude=*.txt Creating tar.bz2 archive file This can be achieved via the example command below : There is a lot more you can perform with the powerful –exclude switch since it can also accept patterns.For instance it is possible to archive a whole folder and at the same time exclude all. Tar -czvf file_ /home/folder –exclude=/home/folder/examples –exclude=/home/folder/single_file.txt In some circumstances, you may want to exclude certain files or directories from being compressed when you want to run tar on a parent directory.This can be done by using the –exclude switch for each file or directory to wish to exclude.įor instance you would like to compress the directory ‘/home/folder’ but you do not want to include the folder ‘/home/folder/examples’ and the file ‘/home/folder/single_file.txt ‘, here is what needs to be done : Excluding Specific files from being compressed In order to display a list of the content of a tar archive file, you would just need to run the command below with the option t : Tar -czvf home/dir1 home/dir1 home/dir3 home/dir4/singlefile.mp3 Listing the content of a tar archive file To compress the directories home/dir1, home/dir1, home/dir3 and home/dir4/singlefile.mp3, just issue the command below : The tar command can be used to compress multiple single files or multiple directories or a mix of both since in Linux, a directory is also a file.You would just need to provide the list of directories or files in cascade as shown in the example below : Compressing multiple directories or files
#Tar zip folder how to
How to tar a file in linux | Linux tar directory | Linux tar folder Tar -cvzf new_compressed_ net2_dmin/Downloads/ The following command will compress an entire folder net2_dmin/Downloads/ as well as its sub-folders, or in other words, it will perform a recursive compression on the whole directory : Let us first create a tar archive file for a specific directory.

In the article, you will learn how to use the tar command in order to extract and create archive files, display and verify the content of a file as well as how to add directories or files to archive, etc… Creating a tar archive file The complexity stems from the many settings and options that you can use with tar. The tar command is not so straightforward to use for beginners. tgz files which are also called ‘tarballs’. The tar tool, which stands for ‘tape archive’, is one of the most important utilities for system administrators in the Unix/Linux world. One of the most commonly used commands to compress and extract files is ‘tar’.
