Welcome everybody to this tutorial. Today I'm gonna go over a few more commands
with you. The first one that we shall deal with is the command man. So, man
actually is basically a manual, or man pages, for a specific command. So for
example, you can type in man ls and it's gonna tell you everything that there is
to know about the LS command. Sometimes the help part
of the command, so ls - -help, is not formulated the best, and you get a
list of arguments, but for example, you don't get the description of what each
one of those arguments does. You only get the syntax of the command and how you
should type it in, but you don't really know what will a
certain argument do to the command, how will it modify. The man pages also have a
help menu. So if I just type in man - -help, you see that I have a lot of
options here. Most of these things are actually related to
searching through man pages, or searching for the right portions of the
man pages, and formatting their output. But, I didn't really find it necessary
over the course of the years to use most of these. Basically, man and a certain
command will suffice.
Anyway, aside from that, I would recommend that you just go ahead and read through
them. Just see what options you have. You don't need to memorize them as you
always have them in the help bar. But, just have a look at it and that will
be sufficient. It's a good thing to know how to use the man pages, and just to
know that they are there, so that you can refer to another source
if the help menu doesn't actually suffice. Let's just go ahead and clear
the screen. The next command which I wanted to deal with you is touch. Touch
is used for creating files. And in combination with this, I will also teach
you how you can actually search through your system for a certain file. Now usually
there are two methods, one is preferred over the other. For example, you have
locate, so very simple, plain English language, and you have find. Now locate is
a lot faster than find, but it does require the database to be updated. And
don't get intimidated right away, the process of updating the database
is basically a one word command. That's it. Anyway, before we get into that, let's
just go ahead and see how touch works. touch, and let's say that I want to
create file one, file one. So this is just a reference thing that I'm creating, you
can basically smash your keyboard here and name your file. There are some
limitations as to how you can name your file, but generally you can pretty much
name it to anything within, pretty much anything that suits you. So,
let's use file one. Let's do it like this, file_01. If I
press ENTER and then if I list it, you can see that the file_01 is there. But
look, there is a shortcut to the LS. If you don't want to do this, ls -l
for the long listing, which is generally more preferable than
just LS, you can simply use the ll command. And if you use the ll command, by
default you will be you will be given a long listing for that directory. ll works
pretty much the same as LS, so you just type in ll. You can also specify a path,
so let's say root. Simple as that. And you can also say ll -R /root/,
you see it gives a recursiveness here. So it works in the same way except you just
type l twice, and press ENTER, and get a long listing. It saves you a ton load
of time, trust me on that one. Anyway, we have created file_01, but we can also
create multiple files like this. It is a rather fast way of doing
that. So we just do touch, and you can also specify a directory where you want
the files to be created. For example, I can go ahead and type in
Downloads/, and then I can say File_02. Downloads/,
File03. And then I can change the directory path, I can say, OK, now I want
you to go to Documents/. And I'm gonna say File, so I messed it up with the
03, I'm gonna fix it shortly, I can say here File_04. So it gives you the ability to
create files pretty much anywhere in your system where you have a permission,
by a single command line. Very useful. We press ENTER and there we go. It has
indeed created them. You can confirm it by doing the listings. So, ll Downloads/, there
you go. So File_02 and 03, and you can see there is another file, it says Find_Me,
I've used it to conduct some tests previously. If I go ahead and type in
Documents, here you see that the File_04 is indeed there. Just go ahead
and clear the screen, and we will deal with the subject of 2 more commands which are find
and locate. We're gonna deal with find first. You will use find only if you
know where something is in specific. You definitely don't want
to use find to search through your entire system because that's gonna take
a while. Not a pretty sight, I can tell you that, not a pretty wait. But, here
you go, you can type in find. That's why we use locate, that uses a database,
that's much faster. That can search through the entire system in practically
no time. So you type in find, and then you're gonna
specify the directory in which you want it to search. You don't need to
specify the directory, you can just go ahead and type in your search pattern
here with an argument. But rather instead, I want to specify the directory
because it would be highly inefficient to actually just say go ahead and search
through the whole system. Although, sometimes we need to do that, and that's
why locate is so nice. I personally always use locate instead of find, but I
just figured I would show it to you anyway. Let's say that I want to go into
my home directory, and there I will conduct the search. So if I type in -name,
then space quotation marks, I will say "File_01". Search, excellent! So it has
found it relatively fast. it says /home/RandomGuy/File_01. It has been found
indeed. But, what if why I did this? What if I changed this letter to a lowercase
letter? Guess what, nothing is found. It does not exist. Linux
is case sensitive. I believe that I've mentioned this previously. If not, oh well.
And two files having the same name, the only difference being lowercase letters
and uppercase letters, are two completely different names for the Linux system. So,
it is case sensitive to the point of extreme, and you should all be very much
aware of it. If you want to ignore the case, the usual argument for the
command, which deal with text formatting, is - i. So you just add -i to the
name and you see it has indeed found it. Usually, - i is to ignore something.
Generally, in all commands. Anyway, I could have just said, if I don't specify a
folder path, let's see where I am at the moment. So pwd, okay, so
I'm in home and random guy. And if I am in the current working
directory where the file is located, and if I do this, it's gonna find
it. But, suppose I am not. Suppose I do go and change it to root.
What has happened here? Well, first of all, we have been issued
permission denied for a ton load of folders. If I do ll we are unable to
access most of these folders as our current user. So, find will not even
be able to look for them there. That's the first problem. The second problem is
that even though it can access the home directory it hasn't actually found it,
because it is only looking here.
There we go so all of these things are permission denied,
permission denied, you are unable to access it. Be sure that you execute a
find command from a place where you have access to the folders and their
subfolders. Please be aware of that. Otherwise, you will not be able to
actually execute find at all. You will just get the same error that I have
gotten. So, here we go, I have typed in find, and it says iname and it says File_01.
Excellent! So it has immediately found it here in home even though I'm in my
root directory, no problems, so it does jump in to the folders recursively which
is very nice. But, look here where it tries to look for the file, it says
permission denied, permission denied, permission denied, you cannot access
these files or folders. And provided that your file is in one of those places, it
will not be able to find it at all. That can be extremely problematic. That's why
we need root permissions, sudo and su. Later on we will deal with that, but for
the time being I just want to this. Anyway, if I go ahead and clear the
screen, there is another command which we can use, which is very nice, I personally
prefer to use it, it's called locate. And if I just type in locate, so File_01,
oh, what is this? It hasn't found anything. What could be the problem? Well, as I
said, locate uses a database, and that database is updated on a daily basis which
is resource inexpensive, but also inefficient.
However, the beloved Linux creators, and the locate creators, developers, have left
us with a very nice option here, you just type in updatedb,
press enter, can not open. Oh, yeah, okay. So one more thing, you
you cannot do the update without the root permissions. In order to
obtain root permissions, well, you just type in an su, press enter, type
in your root password. You're not going to see anything here, it'll be blank. This
is done as a precautionary measure, and of course I've typed in the wrong
password. You see when I type in my password nothing is shown. In Unix, Linux
like systems, every time you type your password into the terminal, usually 99%
of the cases, the length of the password will not be shown. It will not show as
though you're typing anything. Don't worry, it's not broke, it's just a
security precaution. So that if somebody's watching
over your back, they won't be able to see the length of the password on the screen.
Which is a very nice feature, and I would very much like for Windows to implement
it as well. Although, it is not really practical, as I say, you just have to get
used to it. Because even though you're typing something, you can't see anything
on the screen. I would also like some other services, for example like Gmail or
Amazon as well for cloud hosting, and stuff like that, to actually implement
that version of authentication so that the passwords are, so that the
lengths of the password are not shown. Because if somebody has the length of
your password, the amount of possible combinations reduces drastically. Anyway,
now that we are root, let's go ahead and clear the screen. So you can
see that I am no longer random guy, I am root. This is my hostname.
I'm gonna change the hostname later on, but for the time being this is the one.
So, I am logged in now as root, at this hostname, at this machine, let's type in
updatedb. Excellent! And let's type in locate again. So locate, and what do we
need, we need File_01. There we go, it has found it immediately. But look,
you can type in - -help, and there is an
ignore option here, there you go. Look, it is the same, exactly the same, as
with the find command, so -i. Clear, type in locate -i File_01.
OK, let's kill the capital letter. Excellent! So let's just change the name
a little bit more. Let's type in this, this, it's still gonna find it. So, no
problems. But, let's say you don't know the whole name of the file, you just know
the fragment of the name, or the portion of the name, or something of a kind. Well,
that can be problematic. So, what you want to do is type in locate -i, and
here you can actually just type a fragment of the file name. So, I don't
know, let's say it's like, this is gonna give me too much stuff, but let me just
show you. So, File. Look at how that stuff we got, and I don't want to sift through
all of this, but I can assure you that the name is actually within this.
However, you do need to actually filter it a little bit more. So, let's say
File_0, there we go. It has indeed found what we were
looking for. And in addition to that, what we were looking for, it has also
found anything else containing this particular pattern.
Anyway, the file is actually contained here as well...
somewhere, God knows where, but if you don't actually know anything,
if you just know a fragment of the name, then you're actually going to have to
manually sift through this. Unless you are able to learn more, or guess more, about
the name of the file. Eventually, if you sift through all of it, God
knows where, somewhere I guess. But, I mean if you're
looking for libraries, or something of a kind, you generally know that they're in
user share lib, somewhere of a kind, or if you know where you've
approximately saved something, you don't need to search through the entire file
system. You can just specify a path, and then a name to the path, and you can just
specify a path. Hold on, let me show you how to do that with locate. Let me just do
this, so locate -i file_0. And if I say home, okay, so it has it actually been able
to find anything? Yep, there we go. So in addition to a ton load of stuff
which is basically your home directory, as it has taken that as a search pattern
as well, it has actually managed to find this. But, this is not what we're looking
for, this is not good enough, because it is taking the folder path as a search
parameter. So, it's giving us more results than we generally need. So this is no
good. What we need is the help menu, so
- -help, and we need to actually find a
way to exclude the path to the file. I'm sure it is here somewhere, so let's take
a look at it. I have an approach, so that I am putting myself in
your shoes, and this is how you would do it if you wouldn't know how to do it in
the first place. This is how you would learn how to do it.
So basically what do we have here? You always go to the help and you figure out
from there. We have -A, what does that do? Only print entries that match all
patterns. No, not really. -b, match only the base name of the path
names. This could it. -c, only print number of found entries.
Nope. Use DBATH instead of default database.
Nope, let's just use the -b option. So,
locate -b, and let's go to /home, and then space File_, I don't know, 0. We'll
play around with it more. Excellent! So what have we gotten here? It says
in the...oops. My mouse seems to be running away a little
bit. It says -b, base name, match only the base name off the path names. Very
simple. It will will just find the last
entry, and that will be it. Excellent! So, within the home folder and
within all sub directories of that folder, please look for anything, any
pattern, please find any file that contains this
particular pattern which we have given it. So, if you compare let's say this to
this, it's a lot shorter, right? You have significantly downsized the amount of
possibilities. Very useful command, people use it on daily basis. Just don't forget
to update the database. It is necessary for you to do so if you want to find
stuff because it is updated once a day, and it's not enough. You just need to
update it manually and you will solve the problem. There are ways to configure
it to update on a more frequent basis, but there is no need. You're just consuming
resources. Rather instead, just type in updatedb and it's gonna be done in
milliseconds. Then find whatever it is that you are looking for without any
problems, whatsoever. Anyway, I bid you all farewell, until next
time.