Transcript from the "Command Line Exercise" Lesson
>> So that was the introduction. Not too bad. Everybody still with me? So now let's dive in. Let's dive into terminals in the command line. Let's dive into VIM, how we're going to edit files. And let's talk about shells, the thing that the terminals are running, the application itself, and the way it talks to the computer.
[00:00:23] So the command line at the core, it's the most efficient way of talking to your computer. I'm gonna go ahead and say it's the most low level way of communicating with your computer. I'm sure there's people that will disagree with me and say, I write assembly. But that's not a super efficient way of talking to your computer.
[00:00:46] I generally consider the command line the most efficient, the fastest way of talking to your computer and getting to do things. So it's really important we become familiar with it, because most of what we're doing today will be in the terminal. I know that you'd be like, man, the terminal, it's so boring.
[00:01:03] There's not even colours and images. But by the end you'll see how powerful it is and how someone who's really good at working with terminal, good at the commands, can do incredible things much faster than any other way of doing it. So the terminal is fast. It is, I keep saying it, but it is the fastest way of talking to the computer.
[00:01:27] There's no gap. You're talking to the operating system, essentially, through the terminal. It's consistent. So the terminal that I'm running here, the commands I'm running here, will work on the server we're gonna build here. And it'll work on any server, as long as it's running the right terminal on the right operating system, but actually the operating system doesn't matter as much in most cases.
[00:01:48] And that's amazing. It's very portable. And there's low overhead. A terminal just sits there waiting and waiting and waiting and waiting and then executes some command, and then it's done. There's no fluff. It's very straightforward, very functional. So that's why we're gonna get really good at the terminal.
[00:02:09] All right, our first exercise for the day, Welcome to your terminal. So I use something called iTerm. I think a lot of people are familiar with it. So, I'm a big fan of iTerm. Mac has something built in terminal. I mean, it's fine. It'll work. Pick your own flavor.
[00:02:30] But my favorite thing about iTerm is split panes really easily. And if you're running a lot of complicated commands, you can drag and drop them. You can make it look however you like. So feel free to use iTerm, feel free to use the actual terminal itself, doesn't matter as much.
[00:02:52] The shell matters but we'll talk about that in a second. So in your terminal now ,here are some common commands, some of these you've probably seen, some of these you may not have seen. ls is probably the most common one, [LAUGH]. Where am I now and what are the files in my current directory?
[00:03:10] cd, of course, is change directory. If you need to make a directory, mkdir. If you need to remove directory, rmdir. We probably won't use rmdir too much because rmdir doesn't work if the directory is not empty, which is kind of annoying, you have to use rm instead. cat will show the file contents.
[00:03:31] man is really important but you will learn it's not as useful as you would think, because it's very difficult to parse, but it will save your butt, because every program we're gonna run today has a manual page, which is fantastic. That's what I love about all these things is somebody somewhere has documented all the functionality of these programs.
[00:03:51] less will show the file contents by page. touch will create an empty file. So we use it a lot from like, hey, I need to create a tmp, touch tmp. Funny enough, touch doesn't actually create an empty file. It actually just modifies the most recently accessed date time.
[00:04:09] But in doing that, it generally creates a new file. Yeah, fun facts. I got a lot of them. All right, rm, we talked about will remove a file. Generally the command for rm we're gonna use is rm -rf, so recursively remove all the files. And then echo just repeats the input.
[00:04:29] So for this exercise, navigate to your home directory. Then I want you to make a directory called temp. Then I want you to move into temp, list all the directory contents, make a file called hello. Then list the directory constants again, move out of temp, and then delete that directory.
>> So to clarify, when you say touch doesn't actually make a new file, it just sort of does something with the current date time, do you wanna elaborate on that?
>> Yeah, so it's a great question. Touch just tells the operating system, hey, let me update the last modified time.
[00:05:08] And the operating system says, for a file that doesn't exist, it will say, okay, I've updated that time, but the file didn't exist, so I just created it for you. Because this, especially in Linux-based systems very different from Windows-based file systems, where these files don't necessarily have types.
[00:05:26] So in Windows every file has a type, like an exe file called executive file, a dll, lots of different types. Linux, you can have any sort of file. So hence, it's easy for the operating system to be like, [SOUND], there you go, cuz it has no other association other than the name and the last access time.
[00:05:50] Yeah, bit of fun trivia. Good question.
>> If I'm on Windows 11, is there any way for me to run these bash commands?
>> Yes, there's something called the Linux subsystem. It will take a while to install on your computer and you'll have to do a restart, but I was at Microsoft a few years ago and I met the person in charge of the Linux subsystem for Windows and they were super proud of it.
[00:06:20] They're like, we got Linux working on Windows, this is fantastic. Like heresy at Microsoft. But yes, if you wanna use these commands, you can use the, I'm pretty sure it's called the Linux subsystem or the Windows system. You can look it up but like I said, I've done it before I'm on my home computer where I do use Windows, but it does take a while to install.
[00:06:43] And the paths are gonna look a little bit different, cuz forward slash and back slash, but it is possible.