Check out a free preview of the full Full Stack for Front-End Engineers, v3 course
The "Command Line Solution" Lesson is part of the full, Full Stack for Front-End Engineers, v3 course featured in this preview video. Here's what you'd learn in this lesson:
Jem walks through the solution to the command line exercise and demonstrates using the manual.
Transcript from the "Command Line Solution" Lesson
[00:00:00]
>> Let's work through this exercise and then I'll show you how to look up things, both in the man page and on the Internet. Don't be afraid to Google things. You will see me Google things in this class because again, I don't remember all the stuff off the top of my head.
[00:00:13]
No one does, and that's okay. What I've learned about software engineering in all my years is you seem to know what to look for, when it comes to solution finding. So hopefully this exercise wasn't too tasking for you, it was probably really simple, if you had any sort of familiarity.
[00:00:30]
But I wanna get you warmed up with your terminal on the command line because this is where we're gonna be doing all our work. So let's go ahead and fire this up. So, the first step was navigating to your home directory. Your home directory, you can shortcut using the tilde.
[00:00:52]
So cd there, and if I wanna say, am I sure I'm in my home directory? So we'll say pwd, which is print working directory. So if you wanna navigate your home directory, the tilde is gonna be faster but you can always say /users/ whoever you are. And I guess not everybody knows this, but you should.
[00:01:11]
If not, I'm about to blow your mind. Tab autocomplete works very well. So if I'm like, who are in the users directory? I can just jump to Jem, that's me. I just type J and I'll tab and takes me there. But cd tilde is the one you probably just need to remember cuz a lot of what we're gonna do is in the home directory.
[00:01:32]
So next, let's make a directory called temp. So we're gonna use the mkdir command, mkdir temp, and if we do a quick ls, we'll see there's something called temp, and I've made a few other temp files there too. So let's move into temp, All right, let's ls, this should be empty.
[00:01:54]
Let's make a file called hello. So we can just touch hello, we ls again. We see there is a file now called hello. And again the file has no extension, has no type, it's just a blob of data on your hard disk right now. So next was to list the directory contents.
[00:02:13]
We said ls, list contents. Why is it called ls? Now I'm curious. So I'm gonna man ls, so the manual page for ls. It does not explain why it's called ls. Sometimes what I love about the man pages is they are standardized in terms of the name, the description, things like that.
[00:02:36]
But it's really dependent on the person who wrote it and at what time they wrote it, which is like a fantastic look into software engineering itself. Sometimes these have colorful history of the commands. Sometimes they're snarky. Sometimes they're super deadpan. The man pages are like a hidden gem in the software engineering world.
[00:02:56]
I was really hoping this would explain why ls is called ls and not ld, it does not, that's okay. If we scroll down, we can see some of the flags that we can use. And the flags I like to use, I won't go through this whole thing, cuz man pages are very, very, very long.
[00:03:16]
But if you wanna find something, you could type a forward slash and I'll say -a is what I'm looking for. And so forward slash in the man page, and actually, most of the ways of listing file contents, which we will talk about much later. But for now, less or cat or any of these forward slash and what you're looking for will help you find in the man page.
[00:03:39]
So the ls command or the flags that I use a lot is ls-la. l will show the details, the permissions, the size, last modified time, etc. The a will show the hidden files. So by default, dot files aren't seen. So something like your gitignore won't show up in a standard ls.
[00:04:03]
And you'd be like, I'm pretty sure it's there, but I haven't seen it. You just need to use the -a command. All right, so we've listed directory contents, let's move back out. So how do we move out? We cd, so that's change directory, that will actually make sense.
[00:04:18]
We're gonna say dot dot, and now we're back one level up. Now we can cd ../ ../ ../ ../ as far as we want, but we actually can only move so far. The file system doesn't go to infinity, it goes up to /. Slash is known as root, the root of your file system.
[00:04:41]
We can say ls there, and you see all the things that compose your operating system and your file system itself. But that's not really where we're trying to be. We generally don't mess anything in root. If you're ever in root, you probably shouldn't be, you really don't ever need to be here unless you really know what you're doing.
[00:04:57]
So let's go back home, and you remember the shortcut for going back home, cd~. So much faster than saying cd/user/ whatever. And then our next command, we said we're going to delete temp. Remember I said rmdir doesn't work if there's anything in the directory? Yeah, by personal opinion, and I know the Linux fanboys will probably jump on me.
[00:05:25]
I don't know why rmdir exists. I just rmdir exists, I just rm everything. It's a cool command, but generally we're almost never gonna use rmdir. We're always gonna use rm. So we're gonna say rm temp. We're saying temp is a directory, cuz rm only works for files, so we can force it, we say rm-rf.
[00:05:48]
That way it forces the delete, whether it's a directory or not. It'll delete anything, which is a dangerous command. And then r is just recursive. It'll go through and delete everything. But let me double check that r. I'm saying it's recursive cuz my mind is there, but I'm not quite sure, so let's look it up.
[00:06:07]
We'll say -r, equivalent to capital R, great. So let's jump to capital R, nope. /R, why you do this to the man pages? I could just scroll up, that's probably what it's telling me. Yeah, so I would say this is the equivalent of recursion. It'll just go through and make sure every single file is deleted versus just the top level file, then you get into a weird state.
[00:06:44]
Mark, was there a question there?
>> Yeah, just a few people were having problems exiting the man pages.
>> Man, see where we man rm, q. Yep, it wouldn't show up cuz I typed q and it just exits.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops