Moving Around the Command Line

Video loading...

  • 0:07
    Moving Around the Command Line with Addison Berry
  • 0:19
    In this video, we're going to be looking
  • 0:20
    at the basics of using a *nix command line.
  • 0:24
    And by nix, it means Linux, the Mac OSX operating system;
  • 0:30
    or, if you're on Windows, if you're using something like
  • 0:33
    a Linux emulator like Cygwin or something like that.
  • 0:38
    We're just going to be looking at some really basic stuff
  • 0:40
    to figure out sort of where you are,
  • 0:41
    and how to move around a little bit from the command line.
  • 0:44
    Real quickly, the first thing I want to point
  • 0:47
    out here is the command line itself.
  • 0:49
    You've got a machine, a directory, and a user.
  • 0:52
    The add1sun is the name of my computer.
  • 0:57
    After the colon, there's a tilde,
  • 1:00
    or what I like to call the squiggly line,
  • 1:02
    and that's a special symbol on the command line,
  • 1:04
    which stands for the home directory.
  • 1:07
    So that's telling me I'm in my home directory.
  • 1:08
    And then, addi is my actual username on
  • 1:11
    this particular machine.
  • 1:13
    That's just my prompt.
  • 1:15
    That gives me a little bit of orientation,
  • 1:17
    and you'll have different prompts on different machines.
  • 1:19
    Now, the first thing we want to do is type in pwd.
  • 1:22
    That is print working directory,
  • 1:25
    and basically what that's doing is telling me where I am.
  • 1:28
    This is saying that I'm actually in users, addi,
  • 1:32
    and that is my home directory.
  • 1:35
    That tilde is equivalent to /users/addi on this machine,
  • 1:38
    and that's a good thing to know just to orient yourself
  • 1:42
    and know where you are in terms of your file structure.
  • 1:45
    pwd, really handy.
  • 1:47
    If you're sort of confused about where you are on your machine,
  • 1:50
    that'll tell you exactly where you are.
  • 1:52
    Now, when we want to actually see stuff,
  • 1:55
    we're going to use the ls command
  • 1:57
    and ls is for listing things.
  • 2:01
    Here is a list of the stuff that is in my home directory,
  • 2:04
    and you can see I basically have a whole bunch of folders
  • 2:09
    in here to organize stuff.
  • 2:12
    If I wanted to see a little more detail on this,
  • 2:13
    what I could do is ls-al. I think of it as ls-all.
  • 2:21
    And when we do that, what that's going to do is
  • 2:23
    give me more information about everything that's in here.
  • 2:25
    We're not going to get into everything that is on
  • 2:28
    this screen here; I just want to point out
  • 2:31
    a couple of interesting things that we should
  • 2:34
    look at that you're getting on this,
  • 2:36
    that you don't get in just a regular ls that
  • 2:38
    can come in handy.
  • 2:39
    The first thing is that you'll notice that some of these have
  • 2:42
    a d at the beginning, all the way to the left,
  • 2:44
    and that means that they're a directory,
  • 2:47
    so that's a folder as compared to just a plain dash,
  • 2:49
    and that's for files.
  • 2:51
    So, the default is just file.
  • 2:54
    We also have an l on this particular one, which is a link.
  • 2:58
    That's a little more advanced stuff,
  • 2:59
    and we'll be covering that in a later video along
  • 3:01
    with some more of this extra info that we have
  • 3:03
    on this particular listing.
  • 3:06
    The one other thing I wanted to point out real
  • 3:07
    quickly here is we have the listing of our folders,
  • 3:12
    like we saw in the regular ls.
  • 3:13
    Notice, we also have a bunch of other stuff up here
  • 3:16
    that has this dot at the beginning of a name,
  • 3:19
    and this can be for files and folders, and basically,
  • 3:24
    in the *nix world, if there's a dot at the beginning,
  • 3:28
    then that means that it's hidden.
  • 3:29
    It's typically not going to show up as sort of extra cruft
  • 3:32
    while you're looking around, browsing around on your site,
  • 3:35
    so if you know you have something that's actually
  • 3:39
    hidden, or you think something should be there, and not,
  • 3:41
    if you do the ls -al, then you'll see all the hidden stuff,
  • 3:45
    as well, and that way you can actually find
  • 3:47
    what you're looking for.
  • 3:50
    Now that we've got that down, let's actually talk
  • 3:53
    about moving around.
  • 3:54
    I'm going to do the cd command,
  • 3:56
    which is for changing my directory.
  • 3:59
    I can just type in the directory name of where I want to go.
  • 4:03
    So if I want to go to downloads, I could just type that in.
  • 4:05
    There's another handy thing, though, that you can do,
  • 4:08
    which is called tab completion.
  • 4:10
    Instead of typing everything in,
  • 4:12
    I can just type the first letter,
  • 4:13
    or as much as I can, and then hit tab and it will
  • 4:16
    autocomplete for me.
  • 4:18
    If I do that with this capital D, though,
  • 4:20
    the first time I do it, my computer is just blinking at me;
  • 4:23
    it's not actually completing.
  • 4:25
    If I hit tab again though, what it does is it gives me a
  • 4:28
    list of everything that's beginning with capital D.
  • 4:31
    It didn't autocomplete at first because there's more than
  • 4:33
    one thing here that begins with a capital D.
  • 4:37
    It is case-sensitive, so this is something to keep in mind.
  • 4:40
    You'll notice in our listing up here,
  • 4:42
    we actually have a folder for Drupal,
  • 4:46
    which also begins with D, but it's a lowercase d.
  • 4:49
    This is a case-sensitive thing.
  • 4:51
    It's only looking for capital D directories.
  • 4:54
    What I need to do is type enough letters in that it would know.
  • 4:59
    A small d gives me drupal, because there's only one,
  • 5:02
    but a capital D, I need to actually do D-o-w
  • 5:06
    to get to downloads, because I also have Documents,
  • 5:08
    with D-o. But once I type enough letters and hit tab,
  • 5:12
    then it knows what I want.
  • 5:14
    Now I'm in my Downloads directory.
  • 5:16
    You can see that we've switched here,
  • 5:17
    because my prompt is actually telling me
  • 5:19
    what directory I'm in.
  • 5:21
    I can also do a pwd and actually verify where I am.
  • 5:26
    I'm going to do an ls here real quickly so we can see.
  • 5:30
    I've gone into Downloads.
  • 5:31
    What's in here?
  • 5:32
    You'll see I'm brought down actually to the end of the list
  • 5:36
    of everything that's in here, and I can, if I go over here,
  • 5:40
    I can scroll up and you can see that there's
  • 5:41
    actually quite a lot of stuff that's in here,
  • 5:44
    and it's made a nice long list here.
  • 5:47
    Now, if I want to actually be able to sort of parse through
  • 5:51
    this a little in a more organized manner,
  • 5:53
    there's another command that we can look at here.
  • 5:55
    And what we can do is do what's called piping,
  • 6:00
    and that is where I take one command,
  • 6:02
    pass it through a pipe to another.
  • 6:04
    So, I'm going to do my ls, and then I'm going to put
  • 6:07
    the pipe symbol, which is if you do shift+backslash,
  • 6:10
    then that gives you a pipe symbol.
  • 6:13
    So, I will pass through this pipe.
  • 6:16
    ls is going to get passed through to a command called
  • 6:18
    less, just l-e-s-s.
  • 6:22
    And the less command is great because it basically chunks
  • 6:25
    things up into pages.
  • 6:28
    When I do it that way, what I'm doing is getting
  • 6:30
    the first page.
  • 6:31
    And then you'll notice, down here,
  • 6:32
    we have a colon and a little prompt,
  • 6:34
    and that's letting me know I'm on the first page;
  • 6:36
    I can keep going.
  • 6:37
    If I hit the space bar on my keyboard,
  • 6:40
    it goes to the next page and I can continue to page
  • 6:44
    through this really long list.
  • 6:45
    And then when I'm done, I can just hit q,
  • 6:48
    the letter q on my keyboard, and that will quit me out
  • 6:51
    of the list and I'm done.
  • 6:54
    So, we've got some basic commands down.
  • 6:57
    Now I've been able to move into a directory and see what's
  • 7:01
    in the directory, but how do I actually move back up?
  • 7:05
    I've gone down into Downloads, but now I want to go back up
  • 7:08
    to where I was before.
  • 7:10
    I can do cd.. Rather than having to remember
  • 7:14
    the name of the directory above me, if I just do ..
  • 7:17
    that says move back one, and that takes me
  • 7:20
    back to my home directory.
  • 7:24
    Let's look at moving around a little bit more here.
  • 7:27
    I'm back to my home directory, so let's go ahead and actually
  • 7:31
    go somewhere else.
  • 7:32
    I'm going to cd into the drupal directory with the small d,
  • 7:35
    and once I get in there,I can do an ls,
  • 7:39
    just sort of see what's next.
  • 7:42
    And then let's go into the docs directory here.
  • 7:45
    I'm going to do a cd docs and just keep moving down,
  • 7:48
    and now I can do a pwd and see the path of where I am.
  • 7:55
    I just sort of always do an ls just sort of obsessively,
  • 8:01
    just to see what's there.
  • 8:03
    But what I really want to talk about here
  • 8:06
    is the fact that I've gone down several directories,
  • 8:07
    and I want to go back up several directories
  • 8:09
    in terms of moving around.
  • 8:11
    If we look at that pwd,
  • 8:13
    so we can see I'm 2 levels down from home. So if I do cd..
  • 8:20
    and then put a slash and dot-dot,
  • 8:23
    say, so 1 directory slash next directory,
  • 8:25
    then that will take me back up the 2 steps
  • 8:28
    to get back up there.
  • 8:30
    This is cool when you have just 1 or 2 levels,
  • 8:34
    but remembering how many dot-dots to put in and slashes
  • 8:37
    to traverse back up can be harrowing at times,
  • 8:41
    so there are other ways that you can get back to
  • 8:44
    the home directory in particular.
  • 8:45
    It's that special key that we have.
  • 8:47
    Remember, we have the tilde, so I can just say
  • 8:50
    I want to cd to tilde, and that means, take me back
  • 8:53
    to my home directory immediately without having
  • 8:55
    to type all kinds of other crazy stuff in there.
  • 8:58
    And then another thing that we can do is actually just type in
  • 9:04
    the full absolute path to my home directory.
  • 9:09
    So, the home directory is /users/addi. Slash is the root
  • 9:14
    that's like, start all the way at the beginning of the paths.
  • 9:18
    Or, I can also, for this, I can also just type cd
  • 9:22
    with absolutely nothing after it,
  • 9:23
    and it assumes I want to go home.
  • 9:25
    When I do that, you can see in my prompt again,
  • 9:28
    that I'm back at my home directory because I have that
  • 9:30
    little tilde showing up for the directory that I'm in.
  • 9:36
    Now let's actually go back down in.
  • 9:37
    I know I want to go here, and as you can see,
  • 9:40
    I can keep typing the full path;
  • 9:41
    I don't have to go one at a time.
  • 9:43
    I've gone down into the roadmap directory,
  • 9:46
    so this time I went 3 levels down in here, and again,
  • 9:52
    obsessively ls-ing so I can just sort of see what is in here;
  • 9:56
    what directory am I in?
  • 9:58
    But again, we're going to keep playing around with
  • 10:02
    a little bit with moving. So let's say I didn't
  • 10:05
    mean to actually come into the roadmap directory,
  • 10:07
    but what I really meant to do is I wanted to go
  • 10:10
    to the meetings directory.
  • 10:11
    What I can do is say dot-dot.
  • 10:13
    I want to go back up 1, and then down on the other
  • 10:16
    side into the meetings folder.
  • 10:19
    That's a way that I can sort of hop over to the next one.
  • 10:22
    I can go over to siblings that way,
  • 10:25
    and that puts me in our meeting directory.
  • 10:27
    A lot of the stuff we've been looking at is moving
  • 10:31
    around relative to where I am now,
  • 10:34
    and I did mention that that slash for the /users/addi,
  • 10:37
    if I wanted to go back to my home directory,
  • 10:38
    had something to do with absolute.
  • 10:40
    Let's just talk about that real quickly
  • 10:42
    here for a second.
  • 10:43
    I've been moving relatively, but what I want to also show
  • 10:46
    is you can actually start from the very root
  • 10:49
    of your file system and type an entire path
  • 10:51
    in and move that way.
  • 10:53
    Instead of moving from the home directory,
  • 10:55
    let's say I actually wanted to go above where my home directory
  • 10:58
    is and I wanted to go to my Applications folder on a Mac,
  • 11:01
    which is up at the root level.
  • 11:03
    So, I would type a slash at the beginning,
  • 11:04
    and then Applications, and that would take me
  • 11:08
    all the way up.
  • 11:09
    So, when I do this pwd, you can see I'm not in
  • 11:11
    my home directory at all anymore; I've moved
  • 11:14
    up out of it because I went all the way
  • 11:16
    back to the root and started from there.
  • 11:18
    You can also change directory to your root just with a slash.
  • 11:23
    That's what just a plain slash on the *nix line means,
  • 11:27
    is I just want to go to root.
  • 11:30
    And when I go here and I do a listing,
  • 11:31
    this is all the stuff that is the root of my file
  • 11:34
    structure on my system.
  • 11:35
    I just happen to spend most of my time in my home directory,
  • 11:38
    which is under root, users, and then addi.
  • 11:42
    If I do a cd again and go back to home,
  • 11:45
    you can see here's my users/addi in relation to
  • 11:49
    that root, that slash directory.
  • 11:52
    Just something to be aware of, because it's definitely a useful
  • 11:56
    distinction that you'll need to know when trying to type in
  • 12:00
    paths and move around on your system.
  • 12:04
    OK, we've done lots of moving around.
  • 12:05
    Good stuff.
  • 12:07
    Get comfortable with it.
  • 12:08
    I want to do 1 more command, which is for getting help,
  • 12:12
    which is the man command, which stands for manual.
  • 12:15
    You can do that with any command, so, man for pwd,
  • 12:21
    and you'll see that the output, when you get that screen,
  • 12:23
    it's got this colon, and that's that less.
  • 12:25
    So it automatically does less; you don't have
  • 12:27
    to pipe it yourself.
  • 12:29
    So, if I hit the space bar, it will page through,
  • 12:32
    and if I hit q, it will quit out of the man page.
  • 12:38
    You can do this on any command, so I can man man and find out
  • 12:45
    all about the man command itself.
  • 12:48
    So, it's really handy, built into all the *nix command line
  • 12:53
    systems, and you can get all those details of
  • 12:55
    what this command is doing and looking for.
  • 12:59
    And then, 1 last, quick little command for you,
  • 13:02
    which can be handy at times, is if you just type clear,
  • 13:05
    you'll clear your entire screen and make it all nice
  • 13:08
    and tidy.
  • 13:09
    That's the end of this video with some basic commands,
  • 13:13
    just to get you started.
  • 13:14
    Next video, we'll get getting into more stuff in terms
  • 13:16
    of actually dealing with files and things like that.
  • 13:18
    But hopefully this gives a little bit of an orientation
  • 13:21
    so you can start to make your way around
  • 13:23
    your file system from the command line.
Loading ...

Moving Around the Command Line

Loading...

The command line can be a scary place for someone not familiar with interacting with a computer through text-only. We are so used to using GUIs to point and click our way through tasks. In this series we'll walk through some of the most common command line tasks to help you understand what is going on and be able to do some cool tricks yourself.

This is the first video in a series that shows basic command line usage for *nix systems, such as Linux, Mac OS X, and on Windows, using applications like Cygwin. This video shows the following commands and spends the most time explaining how to move around your file structure from the command line:

  • pwd
  • ls (and ls -al)
  • less
  • cd
  • man
  • clear

Note: this video was originally released August 31, 2009 on Lullabot.com.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.