Now, this is all fun, but what's the point of navigating a file system if you
really can't do anything. So, that's our next command that were gonna learn.
So, I'm going to change directory to home, to my home directory.
Let's say you want to go up a level, so remember how changing directory with
./ means current directory. If you put ../
that means one level up so, the parent directory. So, right now I'm in
home/nick, if I type ../ and hit enter
it's going to put me in to the home directory. I can type pwd and see that I'm in home. So, again cd ~
is gonna move you to your home directory, ./ means current directory, so you can
type a relative path from that. "/" means the root of the directory and
this means that you're going to be giving the "cd" command the very absolute
path. So, I can type /user/share as this is a file path directly from the
hard disk, and ../ means go up one level. So, I'm gonna change directory into my
home directory and now the next command we're gonna use is "ls" and what that
does is it lists the contents of whatever directory you're in. So, here is
my home directory, here's what it looks like in the files and folders in it. If I
type pwd to make sure my home directory,
I can type ls and that's going to list all of the contents of this directory in
alphabetical order.
Now ls is a big command, there's many options that you can throw in to it, but
we're going to focus on a few. File permissions in Linux are very important.
They define who can do what, to what file. So, for instance the a.out file that you
see there is a binary file from a C++ program that I wrote, that belongs to me.
That means I can run it. How do we know that belongs to me? We can use the ls command separated by a
space, a dash, and the letter "l". Now the -l argument that we're passing means that
we're going to list it in a long way, so we're gonna get some more information. The
left column is the permissions of a file, so owner, user, group. We're not going
to get into permissions right now, but ls-l does list them. It lists the owners user
account and also the corresponding group. So, when you create a user in Linux it
also creates a group, at least during the main installation, and the group's name is
the same as the username, and it also shows the day
modified and stuff. Now what if we actually wanted to list a directory based on some
other things? So, if we wanted to list it in reverse order, let's say, we can type
ls -r and it's going to list it in reverse alphabetical order.
If we want to define file types when we list we can type ls -p
We see that a directory is followed by the "/". Now also there are
color coding so we can tell that directories are blue, and other files are
generally white, but the a.out is a binary file, so it's green. We can also sort based on file size, and
now what we've been doing so far is listing contents of the current
directory we're in. Now that's cool because if I wanted to see every file
that was in the applications directory, I would change directory to usr/share/applications,
and once there I would type ls. This is going to show me all of the files and
directories within this path. Now this works but let's say I didn't want to
leave my home directory, to list the applications directory. You can actually
pass and argument after ls of the path that you want to list, and it will do it. Now
here's a bonus command for the terminal, it's "clear'. What that does is make
the terminal a little less cluttered. So, again if I wanted to list files in
~/documents, I can do that. Let's say I wanted to list them in reverse order, I
could do that.
Now you see that you can start stringing commands together, at least the ls command, and if you're ever
really lazy and don't want to type the entire "ls" you can just type "l".
Thanks for watching this video with me. We're gonna recap here, we type cd to change in to a directory.
We type pwd to print the current directory that we're in, and we type ls
to list all the contents of that directory, and there's a lot of options for ls.
I've shown you a few, if you want more information you can actually type
ls --help and this is going to provide you with all of the options that you can
run with the command, as well as an explanation of what they do. Thanks for watching this video! In
the next video we are going to be going through some more command line stuff,
we're gonna be the doing command line for a little bit.