Bummer!

This is just a preview. You need to be signed in with a Basic or Pro account to view the entire video.

Start a free Silver trial
to watch this video

Sign up for Treehouse

Running Commands

12:36

In this video we will learn how to run commands from the console. We will see how options and arguments can be used to specify the behavior of the command we want to run.


Teacher's Notes

Commands

  • ls (list files)
    • -l (prints long form of file list)
    • -a (show all files, including hidden files)
  • clear (clear the screen)

Extra Credit

Try creating a folder that contains several text files. Try organizing notes using these files.

Video Transcript

  • 0:00

    So now, we have our console open, now what do we do?

  • 0:03

    Let's take a look at what's going on.

  • 0:05

    The console is a text interface--we type in our commands

  • 0:08

    and the computer prints out information in response.

  • 0:12

    Information is printed from the top down, meaning that the latest info is always at the bottom.

  • 0:17

    At the bottom of the console is something called the command line.

  • 0:21

    This is where we type our commands.

  • 0:23

    Now, the bottom is not always the command line.

  • 0:25

    If we have a program running in our console, it instead will be the latest output of the command,

  • 0:30

    and we can't enter a new command until that program ends or we get it out of the way.

  • 0:36

    On the command line, you should see some text followed by a blinking rectangle.

  • 0:40

    This rectangle is our cursor and it's where the text we type will be inserted.

  • 0:45

    To the left is some text called the prompt.

  • 0:48

    The prompt tells us it is ready to accept some text.

  • 0:51

    The prompt can also give us some contextual information.

  • 0:55

    Here, it's telling us the username we are logged in as, treehouse,

  • 0:59

    as well as our current directory, which is here is the tilda.

  • 1:02

    We will learn a little bit more about that in a little while.

  • 1:05

    Finally, the last thing we see on a prompt is the dollar sign.

  • 1:10

    This is commonly the last character of the prompt

  • 1:12

    and tells us where the prompt ends and our input begins.

  • 1:16

    It's not always the dollar sign but 99% of the time it is.

  • 1:19

    The information on the prompt is completely customizable,

  • 1:23

    and from system to system you'll see different information displayed.

  • 1:26

    Don't get too used of this specific prompt.

  • 1:30

    It's just a prompt that we chose to give you for the most relevant info.

  • 1:34

    It was also different on different computers.

  • 1:37

    So, let's run a command.

  • 1:39

    So, here we are in the console.

  • 1:41

    We see some text at the top this is just a welcome message that is being provided to us

  • 1:45

    when we signed in to this computer and then at the bottom we see the command line.

  • 1:51

    The command line at the left here has our prompt, which is everything up to the dollar sign.

  • 1:55

    Here's our username we're signed in as, treehouse, our current directory, which is the tilda,

  • 2:00

    and the dollar sign ends our prompt.

  • 2:03

    Now, we have our cursor here and this is where we will type in our commands.

  • 2:07

    The first command that we're going to run is a command called ls.

  • 2:11

    Ls is short for list.

  • 2:14

    Many of the commands and programs that we used are shorten names

  • 2:17

    for the commands that we want to do.

  • 2:20

    Now, it maybe a little bit difficult to remember ls stands for list when you really just want to list

  • 2:25

    the directories, but as you used it more and more, the one, two, or three character shortcut names

  • 2:31

    are really going to be more convenient than if you were to type out

  • 2:34

    what the command really actually means.

  • 2:38

    Now, while it might be cryptic at first, you have a bunch of small commands you need to remember

  • 2:42

    because you'll be using them so much you'll appreciate how short they are.

  • 2:46

    So, to run our command all we need to is type it in.

  • 2:50

    Type in the letters l and s.

  • 2:52

    So, for now, this is all I want to run--

  • 2:54

    the ls--command and all I need to do to actually execute it is now hit the Enter key.

  • 2:59

    So, I hit Enter and then the console gave me another line of text.

  • 3:04

    Here we see two items, documents and hello dot txt.

  • 3:10

    You noticed it printed out the contents below where I typed in my command

  • 3:14

    and then it gave me another command line with a fresh prompt and a new cursor.

  • 3:18

    So, the output of my ls command shows up directly beneath where I ran it.

  • 3:23

    So, what's the output?

  • 3:25

    We will see two things, documents and hello dot txt.

  • 3:29

    That means inside the folder I'm in right now there's a folder called documents

  • 3:34

    and a text file called hello.txt.

  • 3:38

    Now, these are files that I created for this computer and so I wrote with some hello.txt

  • 3:43

    and now they made the documents folder that exist inside this folder.

  • 3:47

    So, what that mean is there may not be this particular folder and text on the computer you're on

  • 3:53

    but it shows the files that happened to be on this computer and it should be similar on yours

  • 3:57

    if you're using the treehouse console.

  • 4:00

    Then, you'll notice the document is blue, but hello.txt is white.

  • 4:04

    That's one of the cool things about the console.

  • 4:06

    It can display colors and we can actually see there's plenty of colors in our welcome message.

  • 4:11

    Now, we can run perfectly fine without colors and in some cases that's the default.

  • 4:16

    You may not have the color it's really a luxury not a necessity, but the way our computer is configured

  • 4:22

    is a well do color and commands like ls can use color to differentiate things.

  • 4:27

    For instance, documents being written in blue.

  • 4:30

    In this specific configuration means the document is a folder while hello.txt is just a normal file.

  • 4:37

    Now, there are some other colors that may show up that signify other meanings of

  • 4:40

    how the file is configured or how it's permissions are set or what it contains,

  • 4:45

    but for now, we don't really need to worry about it but that's why they're different colors.

  • 4:50

    So, we saw a basic ls command, but let's try something else.

  • 4:54

    I'm going to type in ls and again we can just start typing again.

  • 4:57

    We have a new command line, so our text from our previous command is still visible and if we have

  • 5:02

    so much texts it scrolls pass the screen we will be able to scroll up and down with our mouse

  • 5:06

    as normal to go back and see some previous commands that we ran.

  • 5:11

    So, this new command is going to be ls just like the last one and something going to put a space

  • 5:15

    and use a dash l with this specify is the option long and let see what happens when we run it.

  • 5:24

    Now, we see a slightly different output.

  • 5:26

    However, really the basics are the same.

  • 5:29

    There's two items, documents and hello.txt, but there are some more info.

  • 5:34

    The dash l just meant that we want to see a long form version of this listing.

  • 5:39

    It was nice seeing the items in the short form before

  • 5:42

    but if we want to get more information the dash l option gives that.

  • 5:46

    You can see the first line says total eight and that's because there are actually some files that are not

  • 5:50

    being listed here by default that actually are in this folder and we'll see that in a second.

  • 5:56

    And then, we see our two items and there are different columns of information.

  • 6:00

    To the left here, we see this line of letters and dashes.

  • 6:05

    This specifies the permissions of this particular file.

  • 6:09

    Permissions are used to make sure that files can only be viewed or written to

  • 6:14

    by a specific people on the system.

  • 6:16

    It's how security works in the Posix operating systems and there are three main settings,

  • 6:22

    and we'll see this a little more later.

  • 6:24

    The first column, however, specifies D for directory

  • 6:28

    then there are three triplets of read, write, and execute, word RWX.

  • 6:33

    RWX, then you can see the W is omitted and there's only a dash

  • 6:38

    which means that the W is not provided here.

  • 6:42

    So, these are triplets mean three differential levels of people who are able to access them.

  • 6:47

    The first triplet means the user who created it.

  • 6:50

    In this case, I created it.

  • 6:52

    It belongs to treehouse, which we can see in our later columns.

  • 6:55

    This means the user treehouse has the ability to read, write, and execute it

  • 7:00

    and we'll learn about what executing means a little bit later.

  • 7:03

    The second is a group, which is a lot like a user but it allows you to have multiple users in a group

  • 7:09

    and each file also has a group associated with it.

  • 7:12

    This means the treehouse group can also read, write, and executed.

  • 7:16

    Finally, this is for everybody else.

  • 7:18

    These are sort of public permissions and here we can see the W was omitted,

  • 7:22

    which means that everybody else can read it; however, they are not allow to write to it

  • 7:26

    but they may execute it.

  • 7:28

    Now, we'll be running a little bit more about this later, but if we take a look at this one,

  • 7:32

    we can see that nobody has access to execute the hello dot txt file because executing a txt file

  • 7:38

    doesn't make sense but don't really worry about that.

  • 7:41

    But here we can see the user who created it, treehouse can read and write to it.

  • 7:46

    The group treehouse can also read and write to it and then everybody else can simply read it.

  • 7:52

    We can change this using some other special commands, so that perhaps may be other people

  • 7:57

    couldn't even read it, but these are the default permissions that we've set up.

  • 8:01

    Now, I'm not going to go over every column, but you'll see two treehouses here.

  • 8:05

    There's actually the user treehouse and there's also a group called treehouse, which I belong to

  • 8:10

    and that's pretty common for what we've created a user on the system for there are also to be a group

  • 8:15

    with the same name and since treehouse is also my group and user that I belong to

  • 8:20

    when I created these files, these files are associated with my user and my group called treehouse.

  • 8:26

    Now, we don't really need to worry about group too much,

  • 8:28

    but when you see the second column here that's what it means.

  • 8:31

    Generally, though, we can really just worry about our user.

  • 8:35

    Then, we have our size.

  • 8:38

    For hello.txt, it's 175 bytes

  • 8:41

    but for documents directory, the size doesn't really make sense.

  • 8:44

    This is not the total size of the contents in it just when directories have a size listing

  • 8:50

    they are 4096 usually and then we have the date of the file and then finally the name at the end.

  • 8:56

    So, as we can see the dash l is longer version and that's what we called an option.

  • 9:01

    There's a lot of different options we could pass.

  • 9:03

    For instance, I told you that there's some files that is not listing

  • 9:06

    and that's actually something about Posix operating systems.

  • 9:09

    If you start a file with the dot at the beginning of the file, it will not by default show up in an ls listing.

  • 9:16

    Now, this is useful because it allows us to create sort of hidden files.

  • 9:20

    They exist but they really out of our way when we're navigating day to day.

  • 9:24

    In order to actually see them, we have to pass a different option to ls.

  • 9:27

    In our case, ls-a and now you can see a bunch more files have shown up with dots in front of them.

  • 9:35

    Now, we don't really have to worry about this.

  • 9:37

    These are usually configuration files created by other programs and

  • 9:41

    we generally don't have to worry about modifying them these are called dot files.

  • 9:45

    But, that's why you see total of eight files in here when we really only saw two.

  • 9:51

    Now, we can also pass something called an argument.

  • 9:53

    So, if we type an ls and now we can pass a specific directory that we want to list.

  • 9:58

    Currently, we've been only listing our current directory, but we could pass any other directory.

  • 10:04

    For instance, if I type any path like /etc, this is the name of a folder on our system

  • 10:11

    then its path name is /etc.

  • 10:13

    So, if we type in ls /etc, we can see all of the files at c directory.

  • 10:20

    As you can see, there's a lot of them and we can scroll using our mouse just like we normally can.

  • 10:25

    But, you don't have to worry about these files.

  • 10:27

    We won't be really editing too much in the etc directory

  • 10:30

    where you can just see what a longer directory would look like.

  • 10:33

    If we want to combine some of those options, we could type in ls pass the dash l option

  • 10:38

    and then list at c directory again, and now, we can see all these files, there we go if we just scroll up

  • 10:47

    and then scroll back down, you can see all those files in this long directory and you notice

  • 10:52

    they have different users associated with them.

  • 10:54

    These user called root that's the administrator user of our computer.

  • 10:59

    It's sort of the default all powerful users, which we usually don't use because we want the safety of

  • 11:05

    being restricted to our own file, so we don't accidentally may be delete a system file

  • 11:11

    and you can see there are various different permissions on all these files.

  • 11:15

    And, these are just important files to the computer.

  • 11:17

    Now, here's a quick tip if you want to clear out the backlog of all these commands you've written

  • 11:22

    you can type a command called clear and hit Enter and they'll put your prompt at the top of the screen.

  • 11:29

    You can, however, scroll up if you want to see everything, but if you want to get your prompt

  • 11:33

    from a bottom to a top the clear command will do that for you.

  • 11:38

    So, we see there are three main parts of the command.

  • 11:41

    The command name or the program.

  • 11:43

    This is what we want to do.

  • 11:45

    It's the verb of our sentence.

  • 11:47

    In our example, the command was ls for list

  • 11:50

    because we wanted the computer to list the files for us.

  • 11:54

    The options, which modify the behavior of the command was the second part.

  • 11:57

    This starts with dashes.

  • 11:59

    These were like adverbs modifying the verb.

  • 12:02

    In our example, we used the dash l option to specify that we wanted the long form of the list.

  • 12:08

    Finally, we have our arguments, which describes what we want our command to operate on.

  • 12:14

    Some commands may not require any arguments.

  • 12:17

    For instance, ls default to the current folder you are in, otherwise,

  • 12:21

    you can pass it which folder you would like as an argument.

  • 12:24

    Don't worry about remembering all the options or arguments nearly every command comes with a

  • 12:29

    manual that you can read if you want to know all the available options and usage patterns.

  • 12:34

    We'll see that a little bit later.

Show full transcript

Workspace

You have to sign up for Treehouse in order to create workspaces.

Sign up

Downloads

You have to sign up for Treehouse in order to download course videos.

Sign up

Instructor

  • Jim Hoskins

    Jim is a full stack software developer at Treehouse. When he's not writing code, he's blogging, teaching, or speaking at conferences. On Twitter he is @jimrhoskins.