

- #Untar linux command example how to#
- #Untar linux command example install#
- #Untar linux command example update#
- #Untar linux command example archive#
#Untar linux command example install#
This was because the bzip2 package was not installed on my system, once installed with ‘yum install bzip2’ it worked properly.

Tar: Error is not recoverable: exiting now Tar (child): Error is not recoverable: exiting now Tar (child): bzip2: Cannot exec: No such file or directory tar.bz2, when I first ran the command I got the below error: We can use the -j option to compress with bzip2.
#Untar linux command example archive#
While we could always compress a tar file after it has been created, the tar command provides options that allow us to compress the archive during creation. We then delete the new/test2.txt file, extract it and restore it, then cat the contents to show that the copy from the archive was indeed updated.
#Untar linux command example update#
In this example we append “new text” to new/test2.txt and then update the archive.tar file with this new file. We can update the existing files inside a tar file with newer files on the file system with the -u option, it will only append files that are newer than the copy within the archive file. Now even if we completely delete the new directory, when we extract the contents of archive.tar the directory will be recreated from the archive. Note that this has also copied the directory path, as shown in the output when we list the contents of the tar file. In this example, we add our previously extracted test2.txt file back into the archive.

We can add additional files into an existing tar file with the -r option which will append files to the archive. ~]# tar -f archive.tar -delete test2.txt In the below example we remove the test2.txt file then list the contents of archive.tar which now only has test1.txt left inside. We can also remove files from within the tar file with the -delete option. This way we can visually see what has been added into the tar file without the need to list the contents with -t after the fact.

~]# tar -cvf archive.tar test1.txt test2.txt Verbose output will print the files and directories that are being added to an archive or extracted from an archive. The -v option for verbose can be added to the tar command which will display useful additional information which may be useful when troubleshooting problems. We can also extract multiple files at once this way by adding more onto the end of the command. ~]# tar -xf archive.tar -C new/ test2.txt In this example we first remove the files we extracted from the last example, then specifically extract just the test2.txt file only. Rather than extracting all contents of the tar file which is the default, we can specify a particular file to extract. Rather than first cd to the destination directory, we can use the -C option which will change to the directory specified when performing the extraction for us. Extract Tar File To Specific Directoryīy default tar will extract to the current working directory which may not always be what we want. tar file, it will remain in place after extracting files from it. In this example, we show the contents of the original test2.txt file, wipe it clean, then extract the contents of archive.tar confirming that the contents of test2.txt have been returned from the copy in the archive. We can extract all contents of a tar file with the -x option. Note that we also need the -f option to specify the tar file to run against. We can list the contents within a tar file with the -t option. tar extension, however we use it here to allow us to easily see what the file is. The original files still exist after being added to the archive, they are not removed by default. 1 root root 10240 Sep 2 12:26 archive.tar ~]# tar -cf archive.tar test1.txt test2.txt The -c option is used to create a new archive file, while the -f option is used to specify the archive file to use (in this case, create). In its most simplest form, the tar command can be used to copy multiple files into a.
#Untar linux command example how to#
The practical examples in this guide will show you how to use the tar command in all sorts of different situations. This makes it easy to perform backups and restores of files and directories in Unix/Linux based operating systems. The GNU tape archive command, known as ‘tar’, is used to store many different files together into a single archive file.
