00:00:00 - Alright, welcome to section 103.1. Now this
00:00:03 - is the part where we start talking about the command line which
00:00:07 - is kind of like the heart of all Linux operating systems. It's
00:00:10 - going to be kind of intense, this section talks about Bash
00:00:15 - which is a user shell.
00:00:17 - User shell environment, there it is and we're going to talk about things
00:00:20 - like, the path and how to run commands whether they're inside or outside
00:00:24 - your path. We're going to talk about what environment variables
00:00:26 - are, how to set them, how to unset them. We're going to talk about history
00:00:30 - and completion of commands and how they work together. And
00:00:34 - we're going to actually show you some commands. We're going to show you how to run
00:00:37 - a couple of things and how to run multiple things at once. Basically,
00:00:41 - it's going to be a crash course in using the command line.
00:00:44 - So let's get started, feel free to play this nugget a couple times
00:00:47 - if you miss something because we're going to go over a lot
00:00:49 - of commands and I don't want you to miss anything. So like, like
00:00:53 - I said let's get started.
00:00:56 - Alright the first thing we're going to talk about is the shell. Now the
00:00:59 - shell is the program that's running here when you're in the command line,
00:01:02 - and you can tell, let's have a look at the password file. If you
00:01:07 - look at the password file it defines in here what the users
00:01:11 - shell program is. For example, in my Spowers account here, you'll
00:01:16 - see my user number, my group number, my name, home directory but at the
00:01:20 - very end here, this bin/bash; this is the Bash shell which is
00:01:26 - the shell that I was assigned. There's a lot of programs that
00:01:29 - no one actually logs in and they'll get a shell like a false which basically means you
00:01:32 - can't log in, alright? So this is where it's defined what exactly your,
00:01:37 - your shell program is and we're going to focus on Bash because it's
00:01:40 - the most commonly used and it's the one that tested on in
00:01:43 - the LPIC exams. Now the settings for how Bash behaves are
00:01:47 - stored in a couple of different places. There is a global one if you
00:01:51 - look at the profile.
00:01:54 - So in the etc folder, a file called profile, you're
00:01:58 - going to find this long, global command or configuration
00:02:04 - file. And it does things like it sets what the command prompt
00:02:07 - looks like, I'll show you that as soon as I quit this vi session,
00:02:11 - but it does, see and it shows like if your root to do that, or if
00:02:14 - you're a regular user, to do that. And what that means is basically
00:02:17 - all it's setting is what your prompt looks like and it also
00:02:21 - says, to look in this profile, dot d folder and run those
00:02:25 - as well, alright? We'll look at that as well, but quit this and you'll
00:02:29 - see how
00:02:32 - this is the prompt, right. And the prompt is the user @ the
00:02:35 - host name and then it shows the current directory. Now this isn't
00:02:39 - necessarily what Bash would show you, sometimes Bash just shows
00:02:42 - you, you know just the, the hash symbol there. Sometimes
00:02:47 - it will show you nothing at all. So this is a setting that's in this case globally
00:02:50 - configured in the etc profile command. You can also change
00:02:54 - some of your settings if you go to your own home directory
00:02:57 - and you look, there's also some things like the dot profile command.
00:03:01 - See if we look at that,
00:03:04 - you're going to see here that all the dot profile command does
00:03:08 - is say, oh look for a bashrc command. See some of these point
00:03:12 - at a lot of other things. Seeing we have a, dot Bashrc file, right
00:03:16 - there. So if we look at the dot bashrc,
00:03:20 - there. It's going to show us that there are some aliases set.
00:03:25 - We could do some more aliases if we uncomment that but this
00:03:28 - is the configuration file for your, see there is a big configuration
00:03:33 - file, for your Bash program itself, how it behaves. Alright, so if you
00:03:37 - wanted to change what your, what your prompt looked like or you
00:03:40 - wanted to change some aliases, like if you wanted to type
00:03:46 - ls and have it equal ls color auto, so that it shows results in color.
00:03:51 - Or, you wanted it to be in a different format, this is where you would
00:03:53 - set aliases and things like that. So this is the, the place
00:03:57 - in your home directory. It's a hidden file because it starts
00:04:00 - with a dot, which is another important thing. If you look
00:04:02 - all that shows up in my home directory is this webmin file that
00:04:06 - we used a couple of nuggets ago.
00:04:08 - Well if you type ls minus a to show all, you'll see there's actually
00:04:12 - lots of stuff in here. But they start with a dot so they don't
00:04:15 - show by default. That's how you hide files in Linux.
00:04:19 - So that's important to know that even if it looks like there's
00:04:21 - nothing in there, a lot of times there will be hidden files
00:04:23 - or hidden folders. These are, these blue ones are actually hidden
00:04:26 - folders inside there because a folder starts with a dot
00:04:29 - as well.
00:04:31 - So let's clear the screen here real quick and we'll actually
00:04:35 - run a couple commands. So that you can see how commands are run.
00:04:38 - Now we've been running commands on the terminal for many
00:04:41 - nuggets now, but this is I'm showing you actually how to do it
00:04:44 - now. So this is your official introduction like ten nuggets
00:04:47 - on, how to run a command on the command line.
00:04:51 - Okay, when you run a command you can do a couple things, you
00:04:54 - can simply type the command. Like let's do the echo command
00:04:57 - here. Alright we're going to say,
00:05:03 - Hello. Now I could have put that in quotes if there's a bunch of spaces
00:05:06 - or something, but we'll say echo hello and it prints hello. Now, let's say
00:05:09 - you want to do, you want to do two things at once.
00:05:13 - Then we'll say echo hello and then do an ls.
00:05:16 - So then it does that and it does, so that's the way you can string multiple,
00:05:19 - multiple commands on one line, alright? So let's do, echo hello,
00:05:27 - ls minus
00:05:30 - a; echo Wow.
00:05:33 - There, okay so we have,
00:05:35 - hello, we did the ls minus a and wow look at all that stuff
00:05:40 - there, alright? So that's a, a simple way to string some things
00:05:44 - together. Let's clear this again. Now you noticed all I did is
00:05:47 - type the command. Well the way that you can, you can just type a command
00:05:50 - like we can't just say pink bunny.
00:05:55 - See, there is no pinkbunny command. But what if I made a command called
00:05:58 - pinkbunny, alright? What if I, I'll make a thing real quick here, pinkbunny
00:06:04 - and we'll say that this command is going to echo hello. Alright,
00:06:11 - and this is a little bit, we'll learn this later, we'll
00:06:16 - make it an executable file.
00:06:22 - Alright, so there it is; pinkbunny is our command, right? Clear.
00:06:25 - So pinkbunny is in there and I should be able to just run
00:06:29 - pinkbunny now, right?
00:06:31 - I should spell pinkbunny right,
00:06:32 - pinkbunny. Well they still don't know where
00:06:36 - pinkbunny is stored and that's because Linux only
00:06:40 - looks for executable files in your path or in folders or
00:06:45 - folders that are specified in your path environment
00:06:49 - variable. Now environment variable is something that is set
00:06:53 - in your shell script config files, right. You can look at all your
00:06:56 - environment variables as they currently are, by typing
00:07:00 - env and this
00:07:01 - will printout your whole environment variable list and
00:07:04 - there is going to be a bunch of them, right?
00:07:06 - Some don't make sense, some the shell is bin/bash, we knew that. All
00:07:11 - of this other stuff, like where the libraries are we talked about
00:07:14 - LD library path before.
00:07:18 - Path, this is the one that I want to show you right now, path.
00:07:21 - Now what it's going to do it's only going to run executable
00:07:24 - files, that's why I did that chmod plus x. It's only
00:07:28 - going to run executable files, but only if it finds them in
00:07:31 - usr/local/sbin, usr/local/bin, usr/sbin, usr/bin,
00:07:38 - sbin or bin. So these are the directories that it's going
00:07:42 - to look in, right? So if pinkbunny my executable program, doesn't,
00:07:47 - isn't located in one of those, just typing it isn't going to work. But
00:07:51 - there's the other way that you can start a program and that's typing
00:07:54 - its absolute path. Okay. So we'll type the pwd
00:08:00 - command which stands for present working directory. And it
00:08:03 - tells us we're in the forward slash root directory. So if I type
00:08:07 - /root
00:08:10 - pinkbunny it should run our program. And it did, see it said hello.
00:08:15 - That was what are pinkbunny program did. There is another
00:08:18 - trick you can use. Here let me show you here so that you see that
00:08:21 - I'm not making this up. Ls minus a remember this will show
00:08:24 - us all, all the files and folders in our directory,
00:08:27 - even if they're hidden, right. And others, these should make, well they
00:08:31 - might not all make sense you don't know what all of them do necessarily, but
00:08:34 - there's a couple that looks strange. There is dot dot and there's dot.
00:08:38 - Now those are special directories okay. The dot directory
00:08:43 - means the current directory, dot dot means one directory up
00:08:48 - or the parent directory. So if I were to type cd for change
00:08:52 - directory to dot dot,
00:08:55 - and then type pwd it's going to tell me that our current
00:08:58 - working directory or present working directory is just the
00:09:01 - root directory slash. Okay. So let me get back into the root
00:09:04 - directory. Check to verify. Okay now I'm back in the root
00:09:08 - directory. If I type cd to the dot directory, it does
00:09:13 - that, but you'll see that it took us to the same directory because
00:09:17 - the dot means the directory we're in right now. So we just
00:09:19 - changed directories to our current directory which is a little
00:09:22 - bit silly but it proves the point. So here's where it comes into
00:09:25 - play. Remember I typed that forward slash root pinkbunny. I
00:09:30 - can also type dot forward slash pinkbunny. Does that make
00:09:36 - sense? See we're in that root directory and we just used the dot
00:09:41 - to say current directory instead of typing the whole path root.
00:09:46 - See and this will work as well, so any time you have an executable command
00:09:50 - or you want to reference any file anywhere, the dot directory, the
00:09:56 - dot file is a directory that means this directory. So it's like
00:09:59 - using an absolute path to the, the folder that you are currently in. So if
00:10:05 - that's a little bit confusing have a look back over what we did,
00:10:08 - what we did here alright. That dot, that dot directory
00:10:11 - just means current directory and then we can specify you know
00:10:14 - pinkbunny, run pickbunny.
00:10:17 - Alright and then it runs hello. So that's how, that's how the path environment works.
00:10:22 - Now there's another thing you could do, we could set that
00:10:25 - path thing. Let's
00:10:27 - this is, we did that env, which will show you the entire environment
00:10:31 - right? ABC equals 1 2 3.
00:10:38 - Okay, now what we've done is we've set the variable ABC equals
00:10:43 - 1 2 3. Now we can make that an environment variable
00:10:46 - so that other applications would be able to see that, by typing
00:10:50 - export ABC.
00:10:55 - Now if we type env for environment, we should see our A
00:11:00 - B C command,
00:11:02 - there it is, see?
00:11:04 - We typed env and there is our abc variable that we set.
00:11:08 - And its set to 1 2 3. Now abc doesn't mean anything to any, any shell
00:11:12 - script right now. We can access it if you want to. Echo. Now
00:11:16 - the dollar sign means that it's a variable that we
00:11:19 - want to print. So echo abc; what is abc? It's 1 2 3; so we
00:11:23 - can reference that just like the, whatever we set it to. So by
00:11:27 - putting that dollar sign in front of it. If this is a little confusing
00:11:30 - again, that's why I said you might want to watch this nugget a couple
00:11:32 - of times, but anyway that's how you set an environment variable.
00:11:34 - Well what if we want to be able to run pinkbunny without typing that
00:11:38 - dot? What we would do, PATH,
00:11:42 - equals, I'm going to get tricky here,
00:11:49 - PATH, seen what I've done is; I've set it to the same thing it
00:11:52 - already is. And then I've added, I'm going to add a colon
00:11:55 - and I'm going to put a dot.
00:11:58 - So let's see what happens now.
00:12:01 - And we're going to export
00:12:04 - PATH. So we've done a couple of steps here. I set the variable to
00:12:10 - itself and then I added a colon at the end and then a dot. See how they are all
00:12:14 - separated by colons up here? And then export will put it into
00:12:17 - my environment variable area, right. So now let's, let's env
00:12:22 - and make sure that it worked right. So we have everything
00:12:25 - that was there before and then a dot. Cool so now we should
00:12:30 - be able to run.
00:12:32 - Let's look at ls. Okay there's pinkbunny. We should just
00:12:35 - be able to run
00:12:37 - pinkbunny.
00:12:39 - We can because it's in our current directory but watch this.
00:12:43 - We see the dot dot, and now we're no longer in that thing, in that
00:12:46 - same directory, we can't run pinkbunny. It's going to say command
00:12:50 - not found because it's not in our path. Because right here
00:12:54 - is our dot directory and pinkbunny doesn't live in this dot
00:12:58 - directory, it only lives in the current directory that we're
00:13:00 - in. It only lives right there in the pink directory. So that
00:13:07 - is how the path environment variable works. That's how you
00:13:10 - can set different environment variables and export is the way
00:13:14 - that it puts them into the, you know into your environment.
00:13:17 - And PATH again, this is generally by default but you can change
00:13:21 - this in those configuration files. If you want this to permanently
00:13:25 - be part of your path, you would change that in that like that
00:13:28 - dot bashrc file that we looked at earlier.
00:13:32 - Let's go to bashrc and
00:13:37 - like in this file we could set up different aliases or we can
00:13:41 - set environment variables. One of those environment variables
00:13:44 - could be path just like we did before, path equals dollar
00:13:49 - sign path colon dot, right? If we put that in here then it
00:13:52 - would set our environment variable to that current directory
00:13:56 - as well. Now sometimes you want to do that, sometimes you
00:13:59 - don't want to do that but a lot of times you'll need to know that
00:14:01 - you need to type the absolute path to an executable in order
00:14:04 - to set it. Now, one more thing this is on the LPIC test and
00:14:08 - you know, you might want to know this. Remember we set that bogus variable
00:14:11 - abc. Well what if we want to get rid of that? Well there's a command
00:14:15 - called unset
00:14:18 - ABC and now,
00:14:21 - if we look back up here,
00:14:26 - just far enough;
00:14:28 - see we typed env, that abc variable that we set a little while ago is
00:14:32 - completely gone. We unset it, so the variable abc doesn't exist. If we try to
00:14:36 - echo abc, nothing; because it doesn't exist, alright?
00:14:41 - So that's environment variables. That's how to set them,
00:14:44 - how to unset them.
00:14:48 - And we know how to work with environment variables. So what
00:14:50 - I want to do now is show you some tricks on the Bash command
00:14:54 - line that you can do with the history. Now history, Linux
00:14:58 - or the Bash shell is really great about keeping your history.
00:15:01 - Okay, so it knows everything that I've typed here which is a little
00:15:04 - bit creepy. But if you type history, first you have to be in
00:15:07 - here. If you type history,
00:15:09 - you'll see it remembers the last two hundred and seventy seven commands
00:15:13 - that I've done, alright. Now these should look familiar to you, these are the things
00:15:16 - that we've done so far, pinkbunny etc etc. But it
00:15:19 - goes back to previous nuggets that we've done, okay. All of
00:15:23 - these things that we've done have to do with the things
00:15:25 - that we've typed earlier on right, back when we, oh gosh we were learning
00:15:29 - about all kinds of stuff here and these are the commands that I typed
00:15:32 - on the, on the Bash command line. It remembers that. Now that's convenient
00:15:36 - not just because you want to check on yourself or somebody
00:15:38 - else who was doing stuff, but by pressing the up arrow,
00:15:42 - you've probably seen me do this and maybe you just thought I was
00:15:44 - an incredibly fast typer, which I appreciate but I'm not terribly
00:15:47 - fast. You just type up and it will walk you through the history of
00:15:52 - things you've done. So if you do a command like ls and you
00:15:55 - want to do it again just press up ls, up ls, up ls.
00:15:59 - You can do the same command over and over just by hitting the up arrow
00:16:02 - and going back through your history. It's a really, really convenient
00:16:06 - way to, and you can go down to go back as well, so up and down they
00:16:10 - both work, it's really convenient.
00:16:12 - And that's a great way to, you know redo commands that you type
00:16:15 - often. Another thing you can do, let's say; here I'm going to go
00:16:18 - into my home directory here. Let's say you know it's a really long
00:16:22 - command, like pinkbunny is a lot to type out. So if you start
00:16:26 - typing, two letters let's say and then you hit the tab key,
00:16:30 - it's going to give you all the different options for the executables
00:16:34 - in your path that are like that. So, like you remembered that it was pink something.
00:16:39 - Let's say I know it's pink something hit tab and looks like
00:16:43 - there's only two options. There's pinkbunny and pinky. So I'm going to type
00:16:47 - P I N K B and then hit tab and it's going to complete all
00:16:51 - the way to pinkbunny for me. It's really nice because,
00:16:55 - well it will save you some time, you, you'll end up finding yourself hitting
00:16:57 - tab all the time even if it's a simple command just because
00:17:01 - it's quicker to have the Bash shell auto complete that for
00:17:04 - you. It's really, really nice. So pinkbunny again, it's hello.
00:17:09 - There are a couple commands that are specifically mentioned in the
00:17:12 - LPIC objectives and they kind of don't fit really well with
00:17:16 - this section but they're mentioned in this section. So again
00:17:18 - it's not my job to determine
00:17:21 - when you learn something. It's just my job to make sure that
00:17:23 - you can pass the test right. So one of those commands is
00:17:27 - uname. Now uname will give you a bunch of stuff. If you just type
00:17:31 - uname it will just tell you what operating system you're on.
00:17:34 - But let's say you type uname minus a. Now minus a will give
00:17:39 - you all of the information about your currently running system.
00:17:43 - Right, it's going to tell you again that you're running Linux
00:17:46 - and that the host name is cbt. And the kernel that you're
00:17:49 - running, you know the build number and who built it and that
00:17:53 - it's a multi processor kernel and it's going to tell you the
00:17:57 - date that it was built. It's going to tell you that it runs for
00:18:00 - the i686 processor, it was optimized for that;
00:18:04 - and that its GNU/Linux, okay. So this is a command that just tells
00:18:08 - you what you're running. Why this would be useful. Sometimes you're
00:18:10 - on a system and you don't know if it's a multi processor
00:18:14 - kernel like SMP. You don't know, maybe it's sixty four bit this
00:18:18 - is not. You don't know because then it would say you know sixty
00:18:22 - four. You don't know; gosh, sometimes you don't even know if you are on Linux
00:18:26 - or Unix and this is gonna let you know. So basically
00:18:30 - uname is just a way to tell you information about the
00:18:33 - system you're currently on, alright. So uname is one of those
00:18:37 - things that you need to know. There is another command that
00:18:40 - it talks about and we use this a lot, we've used this already, we're probably
00:18:43 - going to use it in the future. But it's the man command, short for manual.
00:18:48 - So we're going to say let's do, you know look up a command
00:18:53 - history. We just looked at that history command. So man history;
00:18:56 - it's going give you the manual page for the history command,
00:18:59 - alright. So it tells you all kinds of stuff that you can do with
00:19:02 - a command line modifier etc, etc and the man page
00:19:07 - you can just scroll up and down with up and down keys. Q will
00:19:10 - exit for you. If you don't know that it takes a long time to
00:19:13 - figure out that Q is going to exit for you but that's how man
00:19:16 - works. Now you can also do man minus k which is a neat flag
00:19:21 - and that's going to search all the man pages for a specific
00:19:25 - term. So let's do man minus k and search for http. We should
00:19:29 - find that in something. Yeah. Okay we found that in a couple
00:19:31 - different things. We found that in all these http config things.
00:19:36 - We found it in kcookiejar4. So these are all the different
00:19:40 - man pages that have something to do with http. Same thing
00:19:44 - with man minus k file, alright. That should find a whole bunch of them right. All
00:19:51 - of these different commands have something to do with files and
00:19:53 - that's just a way that you can narrow things down, is with that minus
00:19:56 - k. That's also the same as apropos,
00:20:01 - which is again almost the same thing as typing man minus k.
00:20:05 - If you prefer to type apropos you can, but man minus k searches
00:20:08 - for keywords in man pages and that's what it finds for you.
00:20:12 - Now, another thing specifically mentioned is the exec, e x e c.
00:20:17 - Now what this does, here I want to, let's clear the screen
00:20:21 - here. Okay we're going to run bash. I'm going to get kind of tricky on you here.
00:20:26 - I'm running Bash inside of a Bash window just so I can show
00:20:29 - you. Okay, we type ls and then we type exec ls. Okay, now
00:20:35 - something happened that you didn't notice happened. First
00:20:38 - of all
00:20:39 - you can see this is reading from my bashrc file, right my
00:20:42 - dot bashrc file because we've got the color coded ls
00:20:46 - stuff. Now this, if you run exec ls, what this does it
00:20:50 - runs it with, it runs it in a new shell without honoring my settings.
00:20:54 - Okay, it didn't read through my dot bashrc file,
00:20:58 - it just did a standard ls without looking at the, at the
00:21:02 - my Bash environment variables. So that's why this is all
00:21:05 - just black and white text, right because it didn't get that
00:21:08 - color flag. But another significant thing happened. After you
00:21:12 - do an exec command, well what happened it ran the command
00:21:17 - and then exited the shell. That's why I ran an extra one. So now that,
00:21:21 - that Bash command that I ran here, again, I was a shell inside of
00:21:24 - a shell. Well that shell, that inside shell closed as soon as
00:21:28 - this exec ls was over. So two, two different things
00:21:31 - happen. One, it doesn't look at your bash settings. It runs it
00:21:35 - as a new shell, exec does and then it exits the current shell that
00:21:39 - you're in. Anyway that's what exec does. You see that a lot
00:21:42 - of times in a shell script, that you're running like in
00:21:45 - a, in a script program or something, it'll call something with exec.
00:21:49 - Or a place that you want the shell to exit but the program
00:21:53 - to keep running because sometimes you don't want to have this
00:21:56 - Bash shell hanging around. You want the program to run and the
00:21:59 - bash shell just to exit so that just the program is running and
00:22:01 - that's where the exec command, exec command comes
00:22:05 - into play, alright. A little confusing but again concentrate on what's,
00:22:09 - like a story problem back in school, if
00:22:11 - you'll see what's going on, I started another shell inside of it so that I can
00:22:14 - show you what it looks like. Ran the exec command, it did,
00:22:17 - it didn't use my bash settings it just used a generic. It just
00:22:21 - ran ls all on its own and then it exited the shell. So we're
00:22:24 - back to this normal shell, alright. And that just about sums it
00:22:28 - up. Let's look over to make sure that we covered all of the things
00:22:31 - that our initial slide and then we can move on to the next
00:22:33 - nugget where we learn some more about the command line.
00:22:36 - Okay we've learned about Bash. So we, we covered bash and that it's
00:22:41 - your shell environment. It's the most common one. It's what
00:22:43 - you're tested on in the LPIC exams. It's determined in your,
00:22:47 - in the password file what exactly shell environment you're given.
00:22:51 - We learned about PATH. How to set it, how to change it and what it means.
00:22:54 - We learned about environment variables like that abc variable
00:22:57 - we made up, also the PATH variable that we modified. We looked
00:23:00 - at the history of all the nuggets that we've done. Honestly, we looked back
00:23:04 - through alot of the history in that history command and then we learnt
00:23:07 - how bash is really convenient at letting you do completion.
00:23:10 - Right, it'll, if you hit that tab button it'll auto complete things
00:23:13 - for you and give you a list of options if, if there is more
00:23:16 - than one option available for what you are starting to type.
00:23:19 - And then we learned a handful of other commands. In fact we learnt a whole
00:23:21 - bunch of them. We learned ls, we learned pwd, and
00:23:26 - we learned exec.
00:23:28 - And also a bunch of other stuff here, uname, env, history,
00:23:35 - set, export, unset, echo, man, man minus k.
00:23:39 - And then apropos, you know we learnt that too. Now set, now I didn't specifically
00:23:43 - show you this but in other shells, export
00:23:48 - and set these are kind of synonymous. You can set up a variable
00:23:52 - using the set command whereas we set it just by typing the variable
00:23:55 - equals something and then exported it to our environment. But set
00:23:58 - is a, is a way to set environment variables as well. Okay so
00:24:03 - we learned all of these commands some of them being more appropriate
00:24:07 - for the lesson. I'm not sure why they threw uname in there
00:24:09 - but hey, now you know what kernel you're running that's great.
00:24:12 - Okay so again a bunch of commands, a bunch of concepts, concepts
00:24:16 - like the dot and the dot dot and what those directories mean, okay.
00:24:20 - So go back and watch this nugget if, if it seems kind of confusing
00:24:24 - for you because really it's key that you understand how these
00:24:27 - things work. So that the rest of the stuff we're going to learn
00:24:30 - about with the, the Linux kernel and, and everything makes a
00:24:34 - lot more sense. So I hope that this nugget has been informative
00:24:37 - for you and I'd like to thank you for viewing..