Hello everybody and welcome back to the Linux commands part two tutorial.
Now as you may see right here, I have two terminals opened. One I will just write the commands as we do them and in the other one, I will put them in a text file.
So I will open this command.txt.
You don't have to open this file. This is just for me so I know which commands I covered, and which I didn't, and the other one, we will just test the commands in this one.
So before we begin, I just want to mention the command that we did in the previous video, which is the "cd" command. You now know that it stands for change directory and basically just change the directory to another directory from this terminal.
Now, for example, let's say we want to go to the documents directory. We could just type here "cd Documents." But the question now is, if for example you wanted to go one directory back, how do you do that?
Well, there comes the simple command which also starts with "cd," but instead of typing here a directory you can just here type ‘..’ which will basically lead you one directory back.
So if I press enter right here, it will lead me back to the previous directory, to the root directory as you can see right here, print working directory we are again in the root.
And if we type "ls" to list the current folders and files in this directory, we will once again see the documents right here. So basically I just wanted to mention that you can change directory with the "cd" command and you can also go one directory back.
So for example if you had let's say a directory in the documents directory, I just created it with the "mkdir" command, we also covered that in the previous video, it stands for Make Directory, you can see that now in the documents directory we have another one, another directory which I basically called just "directory".
Also, let's go to that directory and you can see that our current path right now is /Documents/directory.
Now, in order to go back two directories, you can just type here two times "cd," and then two dots, and then "cd," then two dots and now we are going to be back once again in the root directory.
So now that we got that out of the way, I will just type it right here so I know I covered that command, and we will clear the screen for the next command.
Now, this one is a simple command for example if you wanted to check out on which account you are currently, which most likely you will be on the root account, you can just type here the command, which basically does what it says.
It's "whoami."
The command basically just asks, “Who is the current user of this terminal?”
Right now, as we can see, it is root.
You can just read it from here. You don't need to even write this command. You can just read it from this first word right here, which will most likely be root unless you have another account.
We will cover in some next videos how to make another account, which could be useful because we do not want to run all our programs as a root user because it can be dangerous.
So in another video, we will cover how to make another user, which you could use for some potentially dangerous programs.
So now I will just write it right here.
This is not really that useful command, but in case you forget or in case a user is named something differently than root you can just check here with the "whoami" command.
Now, there is a command that I used in the previous videos, but never really explained what it does. It's an important command, especially if you are running some of the programs or downloading the programs which are not executables and you want to make them an executable so you can run them in your terminal.
Now, in order to demonstrate this command, I will just go and make a folder called "programs." As we can see, it is right here and I will change my directory into that program.
Right now I will basically just create a simple Python program that we can just call "program.py."
It doesn't really matter.
Right here, I will just code a simple addition program. Just give me one second. It doesn't matter at the moment what I am doing, but we will be also covering Python later on.
For example, Enter first number, b will be for example Enter second number, and c will equal a * b.
Now, this is simple to understand. We basically ask for an input for two numbers you know, just making an addition and storing it in c. Then, we can basically just print that number, that c number, the result.
So we will just type here Result equals to “+ str(c)).
I hope this works. It should probably work.
So we have here a program called "program.py" now it is a Python program, but you might notice that if we try to run that program and you do that by typing here "." then "/" and then the name of the program, you will notice that it won't work.
It will say, “Permission denied.”
Now, why is the permission denied?
Well, if we use a command that we covered in the previous video, which is "ls - la" we can see all the files in the current directory, also the hidden files and our program.py.
Now, what interests us here is this part right here. Basically, these are just mods that are enabled for this file.
R stands for Read, W that stands for Write, and X stands for Execute.
Now, you might notice that in our program.py, we don't have an X which stands for Execute, therefore, we cannot really execute that program. In order to make that program executable we want to type here "chmod + x" and then the name of the program.
Now, if I click here enter and type here "ls - la" again, you can see now that the program changed its color and not only the color, it also added the X which stands for, as I said, "executable."
You can see the difference from here and from here, and that's how you can check if the program is executable or not.
So now, let's clear the screen.
Now, if you wanted to, you can run the program.
It will ask us, “Enter first number,” let's say 3, “Enter second number,” four, and it will say, “Result equals to 12.”
Now, this command is important and you should learn.
It can be used to make any program that is not executable an executable. So now that we have got that command out of the way, I will just remove this. Well, actually I will leave it right here. Maybe we will use it for another command such as "cat."
Let's cover that command right now.
The command "cat" basically just prints out the contents of the file into our own terminal as an output.
So if we type here "cat" and then the name of our file, it will just print out the code that we just typed as you can see right here. It can be used so you don't really open the file in order to read it like this. You can just print it out in the terminal with the "cat" command and it will just print out all the contents from the file.
Now, that is not the main use of this command. Basically, the main use of this command would probably be in some of the bigger files where you just want to find a certain thing in them.
In order to demonstrate what I mean, we will combine the "cat" command with another command called "grep."
Now, basically what "grep" does is if you want to list for example a huge file with a bunch of words, and from that huge file you want to put aside all the words that contain "password" in them.
Let me just demonstrate. Maybe it's easier if I demonstrate it.
Now, we will create in programs file another file, which will be called words.txt and here we will just type here a bunch of words, then 123password123, then a bunch of words, and for example abcpasswordx, for example, and then a bunch of other random stuff.
Now, if we save this file, CTRL + O to save, enter to save under that name and CTRL + X to close.
We can see that right here we have that words.txt file.
Now, in order to see the contents of that file, as I said we can just type "cat words.txt" and we will see all of those words. Here we can with our own eyes find all the words that contain "password" in them.
But let's say for example that this file was much bigger with millions and millions of words, you couldn't possibly just go through all of those words and just find by yourself all of those words that contain "password" in them.
So what you want to do is combine the "cat" command with the "grep" command.
How do we do that?
Well, basically we just start off the same command "cat words.txt" and then we basically pipe the "grep" command.
How do we pipe?
Well, basically this straight line, just type it right here, then you type here "grep" and then the word that you want to be contained in the other words.
So for example "password" in our case.
Now, what this will do, it will list all the words that contain the word "password" in them. As we see, it only listed two words which is "abcpasswordx" and "123password123."
So it is also a very important mix of two commands, which we will be using a lot. At least, I am using it a lot in my case.
Let's continue with another command, which can be right now "echo."
Basically, with "echo" you can just add a word into another file without opening it.
So, if we want to add "John" as a word into file words.txt. you just type "echo John" then this arrow that points to the right, and then "words.txt."
As you can see, the command worked and right now if we "cat words.txt" it will only be "John."
Now, you might be asking, “Where did the other words go?”
Well, if you use the "echo" command, it will basically rewrite the entire text file. So from those bunch of words, it basically deleted all of them and just put "John" in there.
Now, if we use another word, let's say "echo Jake" into words.txt and we "cat" once again words.txt, we can see that John is no longer there, it's only "Jake."
So let me just type here the "echo" command.
One more thing you want to know, which I probably should have mentioned at the beginning and it is really important, is this command right here "apt update" & "apt -upgrade."
Now, this basically is referring to your Kali Linux repositories, and it will basically just check for the updates from there, and in case there are some updates it will download them and you can install the updates with the "apt upgrade" command.
Now, you want to run this command as you finish the installation of Kali Linux, but we will be doing that command in our next video because the "apt upgrade" command will take, after the installation, I believe about an hour in order to finish.
It will download just a bunch of other files and upgrade them, and I don't even know what not. It will just take a lot of time. That's what I know. So we will be doing that command at the end.
So right now, if you want to check out the history of all of the commands you typed previously in this current session of terminal, you can just do that with the simple command which says "history."
It just print right here all the commands that I ran before. So as you can see right here, these are all the commands that we ran before. It's not that useful, but you might need it sometime. I don't use it that much.
The next command we want to do, let's say for example you want to copy the program.py file into another directory.
So we will just create another directory in this programs directory. We will call it "test" for example, and now you can see that we have the "test" directory, which is blue and the green program.py file, which is an executable.
Now, for example, you want to copy this file into the "test" directory. We do that with a simple "cp" command. Well, "cp" basically stands for "copy" and you just type here the file that you want to copy, which in our case is "program.py" and then you type here the directory you want to copy it in, and in our case it is "test."
So just press enter and basically, as you can see right now, if we change directory to "test" we will have also a program.py there and they are identical.
So if we "cat" this program.py in "test" directory, then we go one directory back and "cat" here a program.py, they are basically identical because we copied them.
So let me just put here the "cp" command. We finish that command. But let's say for example you didn't want to copy that file. Let me just delete it from the "text" directory. You wanted to move it. It is no longer here.
If you wanted to remove it from the "programs" directory into the "test" directory, you do that with the "mv" command, which stands for "move," to move program.py to the directory where we want to move it, "test" in our case.
You can see right now that if we type here "ls" in order to list all the files, we can see that the program.py is no longer here, it is now moved to the "test" directory.
So we type here "ls" in the "test" directory, and now it is only here.
Now, this command can be used for two things. In order to move files from one directory to another directory, and in order to rename files.
So for example, if I type here "move program.py" and then I don't specify a directory where I want to move it, but I specify another name for the file. Let's say "anothername.py" which is not a directory, it is a file, it will rename the "program.py" into "anothername.py."
As we can see right here, there is no program.py now, the program is called "anothername.py" and if we "cat" it right here, we can see that it is the same program that we typed before.
So it is also important to know that it can be used for two things, which is rename and move, just so you know.
Right now, we can cover some of the more basic commands such as "man."
Now, this command basically is used for opening a manual for any other command.
So, if we type here "man cat" it will open us a file which will basically give you all the options available for the "cat" command.
As you can see right here, it can be used for any other command. So basically if you type here "man cp" it will open up a manual for the "cp" command where you can see what else you can do with the "cp" command. As it says right here, copy files and directories.
Now, for example, you can type here "man history."
I don't know if it has a manual, let's see. Yes, it has the manual from the history. Basically, it shows the manual for all the other commands. These manuals are already pre-installed on Linux. You will have them with the installation of it.
You can just check out if you forget what some command does or something like that. You can just type here "man" and then "grep" and it will basically open you up with a manual, and you can just read right here and use the command.
So now that we got that out of the way, you will be using manual a lot in the programs later on which you do not know how they work.
So you will be opening up a lot of manuals in order to find out the command that you need to use in order to run that program.
Also, if we wanted to let's say locate one of the files we forgot where we saved it, and we want to locate it, we can do that with a simple command called "locate."
So, let me just try here with anothername.py. Yeah, I don't think it will work like this. Not really sure why. But for example, you want to locate every file in the system which has a word in it, you can just type here "locate" and you will see that it will print a bunch of these files, and they all have in some of the part, they have a word in it.
As you can see, this file has a word in it right here. So kali - password, and then something else. All of these files will have a word in it. Let's say you want to locate everything that has "wordlist" it will also print out all the files that have "wordlist" in it as you can see: wordlist, wordlist, wordlist, then wordlists.list and so on and so on.
So we covered that command as well.
Now, this is about it for this tutorial and in the next one, we will cover some of the commands which are more towards the system that you are using.
For example, in order to check some of the system settings you will be running the commands that I will show you in the next video such as for example shutdown, ps, uname, restart, reboot and so on and so on, and ifconfig, a bunch of those network commands.
So you should learn this. You should remember like these are some of the more important commands that you will be using all the time.
That's about it for this tutorial.
I hope I see you in the next one.
Bye.