Suppose you’ve produced some videos, but they're currently kept in directories along with all kinds of graphic, audio, and text files (containing your notes). You won’t always want to include all the files within a directory tree in your archive. Of course, you can also have tar send your extracted files to some other place using the -C argument, followed by the target location: $ tar xvf archivename.tar -C /home/mydata/oldfiles/ That, in the example, will save new copies of the original files and directories in the current location. tar filename extension isn’t necessary, but it’s always a good idea to clearly communicate the purpose of a file in as many ways as possible.Įxtracting your archive in order to restore the files is easy: Just use xvf instead of cvf. If you’re following along on your own computer (as you definitely should), then you’ll see a new file named archivename.tar. You should also note that using a dot (.) instead of an asterisk (*) in the previous command would include even hidden files (whose filenames begin with a dot) in the archive. The tar command will never move or delete any of the original directories and files you feed it – it only makes archived copies. The * is what tells tar to include all files and local directories recursively. f points to the filename I’d like to give the archive.v sets the screen output to verbose so I’ll get updates, and.the c tells tar to create a new archive,.Here I use three arguments after the tar command: This example will take all the files and directories within and below the current work directory and build an archive file that I’ve cleverly named archivename.tar. In this article, based on content from my Linux in Action book, I'm going to show you the basics of tar archive creation, compression, and restoration. But the truth is that, over all the years and through all the seismic changes to the IT world, tar has lost none of its power and value. That suggests that the tar tool might be a bit old and past its prime. The "tapes" in question would be all those magnetic storage drives that were popular all the way back in the 1950s. If you want the directory name in the tar archive then you could use -f UX_$.tar in the tar command rather than -f UX.The name tar is, by most accounts, short for tape archive. If you want a separate archive in each of your subdirectories (your question is not entirely clear on this) then a bash loop like this would work: cd /home/johnst/lake_dataĬd $d & & tar -c -use-compress-program=pigz -f UX.tar *.UX.csv It would be simplest to change to the working directory first and then run the tar command.Įntering this at a shell command prompt should do the trick (note the lack of quotes):Ĭd /home/jhonst/data_lake/1m & tar -c -use-compress-program=pigz -f UX.tar *.UX.csv (It is often confusing to novice users that although you are using the tar command to make the archive, the processing of the argument list is actually done by the shell and not the tar command). The -C argument to tar means 'change to the directory following this option', but you are not giving it a directory name after the option, you are trying to give it the list of files.Īlso, you are enclosing the wildcard in quotes which means the shell will not expand it to match the files. Your question doesn't quite give enough details to allow for a precise answer (your question needs to be more specific, more detailed, and contain more explanation of what you are trying to achieve) but I think I get the general idea.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |