Hello everybody and welcome to part two of this tutorial. Let's go ahead and save the
file. Press control-O to output the file. It says file filename to write. You can actually
modify it here. You can type in some letters or whatever you want to change the name here.
You can even change the extension if you want. There is no need for the time being. I'm just
going to go ahead and save it as "test." Just press enter. There you go. It says, "wrote
one line. Hit control-X to exit. There we go. Clear the screen. Now, I'm going to use
cat command to get a listing of this particular file, which is far more reasonable than the
previous one, which you couldn't read. The command, by the way, was functioning properly
but it was mostly a binary file. Therefore I mean, it gave you listing but you couldn't
really read anything from it. So just go ahead and type in cat test and there we go. It says,
"some random text goes here." That is the text that we have typed into the test file
and you can cat it like this. These things are very good, especially with files that
you want to make sure not to change them in any way, you don't want to make any accidental
changes or anything of the kind and you want to quickly see what is located within that
file. There is another way of doing this. Basically, it's "ls." Let's go ahead and get
over to "cd etc/apt/." "Ls." We have plenty of files to work with. Let's take sources.list
as an example here. So if I do "cat sources.list" I'm going to get everything that is within
that file as before. It is listed in my terminal, it's here to stay. It's not going anywhere.
There is another command which I could use. Just go ahead and clear the screen. It is
called "less." If I type, "less sources.list" I will be prompted with a new tab where I
can actually view things here. Not a new terminal tab, but a new workspace within the within
the terminal itself. When I press Q I exit and nothing will be displayed here. So very
nice in terms of being neat, organized and so on and so forth. So less and cat are very
nice things. You can use, for example, "cat sources.list" and the command that I have
previously mentioned is "grep." "Grep" means you pull something, grep something from somewhere
else. Here's what I mean by it. Type in "cat sources.list" and you type in a pipe. This
symbol here. It's called a pipe which basically states whatever the output of this is pipe
it to whatever command comes here. So, I'm just going to type in "grep" and let's say
I want to type in, "src." Press enter. Excellent. So it will only print lines that have "src"
in them. Linux is case-sensitive. When you are grepping, it's going to check whether
it's lowercase or not. You can give it an ignore case. You can type this, "-i" to ignore
the case. This time, you're going to get the same output because there are no different
things within this file. You get the general idea. So this is how you would use "cat" with
grep to pull things out of a file. Very important. This is a huge part of the Linux terminal--
filtering through text files. Primarily because we are going to be doing large network scans
and we will want to create files from which we will be able to pool useful information.
We will later in turn pass this information to other tools to do something with. Anyway,
just go ahead and clear to screen for the time being. You also have "echo." Type "echo
"I AM ALIVE"." It will echo these words it literally is an echo. You type something into
it and it echoes them here. Let's go back to the home directory, get a listing and use
exactly the same command echo live. By the way, you can scroll through previous commands
by using arrow key. So using the up arrow key or the down arrow key, you can scroll
back through previous commands and you don't need to retype them. So I am alive. I'm going
to insert this. I will use a ">" and type in "test." This will echo "I AM ALIVE" into
test. It has replaced the contents of the test, which was "some random text goes here"
into, "I AM ALIVE." Very nice command to have. You can change variable names, variable values
with echo and so on and so forth. We will use this a bit more as we progress through
the course. I don't really want to get in-depth here. Primarily because later on when we have
clear examples that directly relate to what we are doing, which is basically testing,
then you will see more advanced usage of pretty much all of these commands-- especially grep.
You have "touch."Touch" is a quick way to create files. So, for example, I can type,
"touch file1 file2 file3." Press enter, "ls." You see, it immediately created three files.
That is a very quick method to create any amount of files. You can specify a folder.
You can create this file in home, this one in var, this one in varlog, and so on and
so forth. Down below, you have "mkdir." Type in, "mkdir" and it makes a directory. So you
are making some sort of a directory. Let's say this the name of this directory will be
"placeToBe." If I hit "ls." There we go. It states that is the does that this file is
actually a directory, which is PlaceToBe. I can even navigate to it and say, "PlaceToBe
ls." There is nothing in it but you get the idea. You can make directories in such a fashion.
Now, if I type "chown" it allows you to change the ownership of a particular file. Since
we only have a single user here, which is root, there isn't really any point in doing
so. If we create some of the new users we could do that. However, we don't need them.
I'll just show you how this would work. For example, if the owner of the file was not
root and you want to change it to root, do the following. Type, "chown," then you would
type the username ":" and the user group. The user group and the username are usually
the same on your home PC, unless you have some bigger servers or something like that.
Then just specify the name of the file. You can type "test." There it will effectively
change the ownership of file test to the username root, who is from the user group root. If
I do "ls la" it states who the owners are and which groups actually owned the files
as well. Clear the screen. There is another more used command. It's called "chmod." This
command allows you to change file permissions. This is something that you will need to use
on daily basis and quite often. Primarily because, you see if I have an executive file
in Linux, for example. Let's just go ahead and type in, "echo hello." I want to that
to test and I want to test to test.sh. "Sh" is basically an executable one, that's a bash
script for Linux that in such a way you can automate tasks. We will deal with it in greater
depth as we proceed through the tutorial. You will need to be acquainted with bash scripting
definitely. Bash scripting is very similar to the terminal itself, so pretty much all
the commands used in the terminal, can be used by scripting as well. You basically just
combine a bunch of them in a file. Now, I want this to be my executable, but you see
the way to to start executables is "./" as stated previously that's the command to start
any executable. If I type in test, and press that, it doesn't give me a list of possibilities.
Now, surely test.sh is an executable, but no you see, it doesn't have a permission to
be an executable file. See here the difference, take a look at this file and take a look at
this file. This one is green, this one is not. Now look at their permissions. So you
see, it has a markation that is executable for all groups, users, etc., while this one
up here does not have such permissions. You need to change that. What you do to change
it is, "chmod." You would type in, "+x." If you want the file to be writable you type,
"+w," if you want it to be executable "+x," if you want to be able to read the file, "+r,"
very simple. There is also a way of doing this with numbers. You can type in, "755."
Don't try remembering all those modes. Whatever you need go on the internet and check. It
can be quite complicated, but these three you need to know: +x, +r, and +w. Also 777,
which is a global mode. This is the mode which is not recommended for actual usage, but you
use "chmode" to actually test or troubleshoot things. For example, if you want to be absolutely
sure that certain actions are not being prevented due to file permissions, you change the mode
of those files to 777, which is the global mode that anybody can do anything with the
file. If you still have an error message you know that it is absolutely not related to
anything in regards to permissions. So, those four things to do need to know. You can just
go ahead and type, "chmod +x test.sh," press enter. If I do "ls la" once again, you will
see that test.sh is now executable. Let me just run it and there you go. If I run this
it's going to echo "hello" on my terminal screen. There's a bit more to go. Not much
more left. There is just one more command that I would really like show you. This can
be a very dangerous command. Indeed, it can mess you up in ways you can't begin to imagine
yet. that is the command "rm." "Rm" is basically remove. Once you remove things with this command,
it's next to impossible to recover pretty much anything. So, if I type in, "rm test.sh,"
it's going to remove it. It's no longer going to be there. If I go ahead and navigate over
to PlaceToBe and I "touch test" to make a new file there. If I go ahead and say "RM
PlaceToBe." It will say "rm cannot remove place to be because it is a directory." This
is a failsafe of the rm. So, you wouldn't delete a full directory because you will be
able to recover it, and that would be really bad. What you can do is type in, "rm -f PlaceToBe."
Cannot remove directory. Okay, no problems. Sometimes you get stuck. I'm deliberately
going to leave this part in the tutorial. I'll just troubleshoot it. So you type in,
"--help." Here you have recursive remove directories and their contents recursively. So, that's
a very nice option. So, let's just go ahead and do that because this will go into the
folder and remove everything within the folder and the folder itself, hopefully. So, just
go ahead and type in, "rm -r PlaceToBe," press enter. There you go. It has deleted it. There
we go, it is no longer there. The "-f" that I have used is force. It will not ask you
any questions. It will delete the folder or file, which can be also very dangerous. When
you're using "rm," you always want to be asked questions. In any case, as I said, I deliberately
left his to show you that even if you get stuck worry about it. I get stuck all the
time. If you don't know what to type in, what argument to pass, just type in "--help." Take
a look at what you can actually type, read a little bit and then use the options. Try
it out, sometimes it will work, sometimes it won't. More often than not, you will be
able to figure it out from the help menu. If you can't figure it out from help menu,
just typed in "man rm" and you can read pretty much everything there is to know about this
command here. If you really can't perform the task, if you can find anything useful
here, forums are your next best bet. Trust me you will succeed in doing it. In any case,
this was a brief introduction some of the basic commands that we will use. Please make
sure that you know what each one of these commands does, at least basic functions. Later
on we will get in-depth, do more advanced stuff and use more advanced commands by combining
them, and so on. In any case, I bid you all farewell. I hope to see you in the next tutorial.