 Hello, and welcome to a video from filmsbychris.com. I am Chris, that's Chris with the K. There's a link in the description to my website. Today we're gonna be talking about archives, tar archives. So we're gonna be working with tar, what is tar tar stands for? Tar archive, or tar tape archive. And so back in the day, storage was really expensive. And one of the ways we would store stuff is on tape. And so we would use tar to put files on a tape. We still use that program, but we're saving the files rather than physical tapes. And it will allow us to take a directory and basically put all the files into one file. Let's go ahead and do that as an example here. So what I'm gonna do here is I'm gonna say tar-c for create, v for verbose. That will list the files out as they're being compressed. If you don't need that in there, if you want it to be quiet as it's compressing, I kind of like seeing the files listed as they go in. And then dash f for the file name. Then the name of the file. So in this case, I'm just gonna call it projects.tar. And I'm giving it a directory, usrlocalbin, which is where I keep all my scripts for my system. And I will go ahead and run that. And you can see it lists out all the files because we had that v option in there. If I list out what's in our current directory, you can see we have the tar archive. If I show a little more information on that, you can see that it is 208 megabytes. There is no compression going on here. This is just the files all put into one file. Now to extract those, it's super simple. You say tar dash x for extract f and then the project, or the file name, in this case projects.tar. And you do that, it's going to uncompress them all. We list it out. You can see, or not uncompress it, but extract them all. And you can see there's a, it extracts the directories. So usrlocalbin and you can see all the files in there. I'm gonna go ahead and I'm going to remove that directory we just created. And we still have our tape archive here. What I'm gonna do now is I'm gonna say tar dash c for create, z for zip. Because again, the first thing we did was just put all the files into one file. But there was no compression going on. To compress, we're gonna use gz or gzip. And we can do that right within the tar command. And I'm gonna say, again, v for verbose. You don't need that, but that will list the files as they're being compressed. Dash f and our project file name. So this time I'm gonna say project.tar.gz. And I'll give it that same directory as before, usrlocalbin. Now again, so gzip can compress a file, but it can compress a directory to the best of my knowledge. Where tar will take a directory or a group of files and put them into one file. So basically you're creating one file that's all the files put together and then you're compressing it. You can see it's taking a little bit longer. When we did the first command, we didn't compress it. It took like a second. That took maybe five seconds. But if we were to list out all our files now, you can see that our compressed archive is less than half the size of our original archive. So we're compressing it, slows things a little bit down when you're compressing it or extracting it, but makes a file size a lot smaller. And you can give it options as to how much it compresses it. And that will slow things down but make a smaller file in some cases. It compressed pretty good here because most of the files in that directory are scripts, which means they're plain text, which means they compress very well. There are a couple of binary things in there that aren't gonna compress so well because well, they're binary files that are probably already compressed to some point. Okay, so we've created a tar archive. We create a tar archive that's been compressed with GZIP. We've extracted it. Let's go ahead and see. Let's say you have an archive file and you want to see what's in that. You wanna list the files. We'll use tar dash T. T, I'm not really sure what T stands for. Maybe table of contents but it will list out what files in there. I'm gonna say verbose F for file. I'll give it the file name and I'll give it the tar GZ file. And there you go. It's listing out all the files and information about them to the screen. So I didn't need to extract anything. So that's great but let's say I'm looking for a specific file so I could do something. I could run that command. Of course I can put it in grep and I can say something like YouTube play and you can see any file that has YT play in it will show up but we don't need to pipe it into another command. Now, if I wanted to look for this file here I could actually just after within our tar command here I can just in quotation marks put the name of that file and it'll list it out. Oh, yep, it's in there. The thing is writing it like that you need to know the full name and path. If I just said YT play it's not going to find that's gonna say is not in the archive. But what you could do is you could do something like dash dash wild card cards with an S. And if I do that might need to put asterisks around there. There we go. Now it's listing everything with YT play in there and it's doing it without having to put it into grep. So that's how you would do that. You would search through using wild cards and use your little asterisks here. Otherwise you need to give it the full file name. But that way you can look through what files are in there and once you know what files are in there you can find the file you want and instead of extracting them all you could extract just one. So again I just wanna make sure okay I already deleted the USR folder. So I'm gonna say now I was gonna say tar dash z x v y and then I'm gonna give it the archive name and then I'm gonna give it the file name that I want to extract. But again I gotta give it the full name so actually let me go ahead and do this again. And let's say I want to extract this file here. So what I would do is I would say tar dash z x v f in our project file name and then the full path to the file we want within the archive. Okay, so we're gonna run that and it's extracting just that one file. If I list out now you can see we have that USR directory and I can look inside that directory and it's just that file. Now again if I wanna extract multiple files that are matched I could do something like this. I could say dash dash wildcards and I can say, whoops, let's try that again. I have a bunch of scripts with YT in it those are my YouTube scripts. So I just go ahead and do that and you can see it's extracting all of those but just those ones with that match. So if I was to list out what's in there now it's extracted all those files. Now, I hope you found this video useful. I will put a link in the description to all the notes of everything I just did so you can look at those, copy and paste them, hold on to those notes for yourself but also be sure to check out my website and that's filmsbychrist.com, that's Chris Decay that will also be a link in the description to my website. It's a great place to search through all my videos and I thank you for watching. Please like, share, subscribe, comment and also check out my Patreon page and there's other ways to support me under the support section on my website. I thank you for watching and as always I hope that you have a great day.