Complete Intro to Linux and the Command-Line Wget
Transcript from the "Wget" Lesson
>> I'm just gonna brief this, Wget is a command that I'm gonna show you very briefly how to use, but I wanna show you another one that I like better called cURL. And I think cURL is a better command to Wget, but again when you're like googling around and you find stuff, you're gonna find stuff that has Wget in it quite a bit.
[00:00:16] And it does do some useful things. So I just want you to know what it is, know how to use it, and then we're gonna spend more time on cURL. So Wget and cURL, they're two ways of getting a remote file, right? And not in the sense of SFTP where you're moving things across the network.
[00:00:34] What you're doing with Wget is like, there is a file on GitHub and I want to go download that file, right? So you're basically downloading something typically from the Internet. It would work on a local network as well, but in our case, we're just gonna be doing it from the Internet.
[00:00:51] So I'm gonna show you where we're on here. So we're down here in Wget, this one right here. And we're going to go download a game, a bash game off the Internet. So this GitHub user right here, mydzo created a bash version of the game 2048, right? Have you played 2048?
[00:01:13] I've played it way too much on my phone. I have gotten 2048, that's how much I've played that game. And someone's gonna come here and say, well I got like 19,000, I was like you know what? Okay, weird flex, but okay, sure. So this user created 2048, we're gonna go download it.
[00:01:29] And so we're gonna run this command right here. So you can copy and paste this if you want to, or you can write it in. I have forked it to my GitHub repo just because in the past when I create these courses, people will change things, and I don't want that.
[00:01:42] So it's exactly the code that this user wrote, so all credit goes to them. And so you're just gonna be getting it from my GitHub, so that I can make sure that this stays stable in the future. Okay, so I'm gonna copy that. You can even put it in here if you wanna see it, I'm not going to steal all of your credentials.
[00:02:00] Man, that would have been a great lesson that I could have taught people. I could have totally made this like some sort of thing which is like, you've been hacked, and have like a skull show up, like 1990s hacker kind of thing. Missed opportunities, I guess I still could after this course.
[00:02:14] I could go in there and I could change it and just scare the hell out of people, and teach them a very strong lesson. But then, I don't know, somebody's gonna get upset. I mean, somebody's gonna get upset anyway that I didn't do it. Anyway, we can see here, this is the game.
[00:02:26] And I went through it line by line, this is fine, you can run it. I'm gonna run it right now for you. Anyway, so I'm gonna cut and paste that in here at Wget. And what this is just gonna do is it's gonna go out to the Internet, it's gonna download this file, and it's going to just leave it with the same name that it came in as, which is bash2048.sh.
[00:02:47] So if I run that, you can see there it's gonna go out, it's gonna connect, it's gonna download it, and you can see at the end of this, and I put the file here called bash2048.sh. Right, make sense? So if you look at the permissions on this file though, by default even though it's a .sh file, you still have to give it permissions to be an executable, right?
[00:03:12] Cuz this is a file that you can run. So you can do one of two things. You can either say bash2048 like that, and you can actually pipe at it directly in the bash, or we can make this an executable file by saying chmod either 700 or we could do +x, I hope we'll just do +x, bash2048.sh.
[00:03:38] So now if we look again at it, you can see that it's nice and green. That's because my LS color show things that are executable as green. And you can see here now it has executable permissions for everybody, right? So now I can just save bash2048.sh. Dot rather.
[00:04:05] And you can see here I am actually now running 2048 in my command line, which is pretty cool, right? So now you're gonna have to sit here and watch me play this until I lose. So you might be here, well, you might wanna grab like a sandwich. I'm just kidding, no one wants to see that.
[00:04:24] But that's pretty cool, right? We were able to download this using Wget off the Internet, and now we can start playing it in here. I thought it was pretty cool, okay? So now, I mean you are welcome to like abandon ship on this course and just play this for the rest of your life or maybe not suggest it.
[00:04:41] But I think then that we can do a Ctrl > C, and you can have like the ability to save the game, I'm just gonna say no. It says you have lost, well, that's nice to them. The thing that was annoying about this is it does actually totally exit your shell whenever you finish.
[00:05:01] So I've actually totally lost control of my shell here, so I actually have to open another shell here. Okay, so the point here that you should be getting is Wget it's like copy, like CP for the Internet. You can say, I know of a remote URL that I want you to go out here and I want you to copy it here, right?
[00:05:21] So you can think of it as like the network version of CP. The thing that Wget is not useful for is it doesn't connect into the pipes, right?. So that's why I'm gonna show you cURL next, cuz cURL, you can pipe things from the Internet into other programs, right?
[00:05:40] Cuz it uses standard in and standard out, whereas Wget is more like CP, right? So it's more like file goes here, file comes here, that kind of thing. Wget can do all sorts of other things as well. It can also do POST requests and PUT requests, and all sorts of stuff like that.
[00:05:57] However, I'm gonna show you how to do all that stuff in cURL, so I'm not gonna show you how to do it twice. I just wanted you to be aware that Wget exists. The one thing that Wget does and that is the reason to know about Wget that cURL cannot do, is it can redo recursive downloads.
[00:06:32] So you can actually recursively download entire websites using Wget, whereas cURL does not have that capability. So whenever you need to do those sorts of like go grab me this entire website, Wget can do that for you. Otherwise I would say, 100% of the time just use cURL, cool.
[00:06:50] Any questions about Wget? All right. Yeah, and again, as always, you can just say wget dash, dash help. This will tell you a lot of stuff that it can do. You can see that it has a lot of capabilities here. So yeah, again absolutely nothing against Wget. Fantastic program, it's been around forever, it's worth knowing about and knowing where it is.
[00:07:21] I just prefer cURL for its ability to plug into the greater Unix, Linux ecosystem.