~]# 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. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |