In this video tutorial we will continue with the Linux command line and cover the ownership and permission commands, chown and chmod. In Linux you have three control groups – individual users, group of users, and global (public). Groups can have read, write, execute privileges, or some combination of the three. We will cover a few different ways you can change permissions via the terminal.
In this tutorial we will continue with command line and cover a few command for finding files. There are two primary commands for finding files, find and locate. Locate is my preferred command, however you need to update the database using the command updatedb. We will also continue using the help pages within the Linux terminal, – -help and man. Also, I will show you how to efficiently find files you may not know the name to using terminal.
In this tutorial we will continue covering the file system navigation commands ls, cd, pwd. We will explore a few arguments that can give you additional output, and how to find help within the Linux terminal.
In this tutorial we will begin a mini-series on the Linux command line. I will cover the commands ls (list), cd (change directory), pwd (print working directory) and clear. These commands will help you to navigate the Linux file system through the terminal.
If you find yourself needing assistance at any point throughout the tutorial series, feel free to enroll in The Complete Ethical Hacking Course Bundle for 1 on 1 help!
Hello everybody and welcome to part two of this command line essentials tutorial.
Let’s go ahead and save the file, so press ctrl + O to write the output to the file. It says File Named to Write, you can actually modify it here. So you can type in some letters, or whatever you would like. You can change the name here, or you can even change the extension if you would like, but there is no need for the time being. I’m going to go ahead and save it as test. Press Enter, there you go. It says wrote one line. Control + X to exit, there we go. Clear the screen, and now I’m going to use the cat command to get a listing of this particular file, which is far more reasonable than the previous one which we couldn’t read. The cat command was functioning properly, but it was mostly a binary file. Therefore, it gave you a listing, but you couldn’t really read anything from it. So let’s 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. The cat command is especially useful if you would like to to quickly see what is located within a file.
There is another way of doing this, the command is called LESS, and let’s go ahead and navigate over /etc/apt/, ls, and here 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, and it’s going to be listed in my terminal. But, there is another command which I can use, let me just go ahead and clear the screen. It is called less. If I type in less sources.list, I’m going to be prompted with a new workspace within the terminal itself, and when I press Q it’s gonna exit, and nothing will be displayed here. So, very nice in terms of being neat and organized. So less and cat are very useful commands.
Next up, we have the GREP command. With grep you grab something from something else. Here’s what I mean. You type in cat sources.list, and you type in a pipe. This symbol here is called a pipe. This means that whatever the output of this is, pipe it to whatever command comes here. I’m going 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 so when you are greping, it’s going to check the case of the letters by default. You can tell it to ignore case like this, -i means it will ignore the case. You’re going to get the same output because there are not any different things within this file, but you get the general idea. So this is how you would use cat with grep in order to pull things out of a file. Very important! This is a huge function of the Linux terminal, filtering through text files. We’re going to be conducting large network scans, and we will want to create files from which we will be able to pool useful information, which we will later pass to other tools to do something with. Anyway, let me just go ahead and clear the screen.
Continuing along, we have the ECHO command. So, echo, and I give it open quotation marks. Let’s say, “I AM ALIVE.” Close the quotation marks, and 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 “I AM ALIVE.” By the way, you can scroll through the previous commands by using arrow keys. So, using the up arrow key and down arrow key you can scroll back through previously used commands, and you don’t need to retype them. So, “I AM ALIVE”, and I’m going to insert this, so I’m going to use a greater than sign, and type in test. So this will echo “I AM ALIVE” into our test file. If I type cat test, you see it has replaced the contents of test, which was some random text goes here, with I AM ALIVE. You can change variable names and 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 want to get in depth here because later on when we have clearer examples that directly relate to pen-testing. Then you will see more advanced usage of pretty much all of these commands, especially grep.
We have the TOUCH command. Touch is a quick way to create files. So, for example, I can type touch, and I can say file1, file2, file 3. Press ENTER, ls, and you see it has immediately created three files. Touch is a very quick way of creating any number of files that you wish, and you can specify folder paths, you can create this file in home, this one in var, and so on and so forth.
Anyway, down below you have MKDIR. So, if I go ahead and type in mkdir, it stands for make directory. Let’s name this directory placeToBe. If I ls, there we go. It states 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.
Next up is the CHOWN command. Chown allows you to change the ownership of a particular file. Now since we only have a single user here which is root, there isn’t really any point in doing so unless we create new users. We are not going to do that as we don’t need them, but let’s do a quick example. If the owner of a file was not root, and if you wanted to change it to root, he would do the following. So, chown, and then you would type the username, colon, the user group. So the user group and the user name are usually the same on your home PCs, unless you’re a part of a larger server, or something like that. Then you just specify the name of the file. We can type in test, there we go. So it will effectively change the ownership of file test to the username root, who is from the user group root. If I type ls -la, you can see here it states who the owners are, and which groups actually own the files as well. Clear the screen.
There is another, more common, command called CHMOD, and this command allows you to change file permissions. So, this is something that you will need to use quite often. If I have an executable file in Linux, for example, let’s just go ahead and type in echo “echo hello” close quotation marks, and I want to output this to test, and I want to move test to test.sh. Sh is a BASH script for Linux. You can use BASH scripts to automate tasks. We will deal with this in greater depth as we proceed through the course. BASH scripting is very similar to the terminal itself. Almost all of the commands that you use in the terminal you can use while BASH scripting as well. Now I want execute test.sh. The way to start executables is ./, as I have stated previously, and if I type in test and I press tab, it doesn’t give me a list of possibilities. Why? Surely, now test.sh is an executable, but no. You see it doesn’t have permission to be an executable file. If we just 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 notation that it is executable for all groups, users, etc. While this one up here, test.sh, does not have such permissions. You need to change that. The way you change it is chmod, and you will type in +x. So if you want the file to be writable, you type in +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 memorize all of those modes. Whatever you need you can go on the net and check, it can be quite complicated, but these three you need to know. It’s +w, +r, and +x, and also 777, which is a global mode. 777 is not recommended for actual usage, but you can use chmod 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 you do need to know. So let me just go ahead and type in +x, type in test.sh, press ENTER, and if I do ls -la, 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 onto my terminal screen.
There is one more command that I would like to show to you. It can be a very dangerous command, it can mess you up in ways you can’t even begin to imagine yet, and that is the command RM. So rm is remove, and 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 remove it, and it’s no longer going to be there. If I navigate over to placeToBe, and touch test, it’s going to make a new file there. If I go ahead and say rm placeToBe, it’s going say rm cannot remove placeToBe because it is a directory. This is a fail-safe for the rm command so you do not accidentally delete a full directory. What you can do is type in rm -f, and then placeToBe, cannot remove directory. Okay, not a problem. I’m deliberately going to leave this part in this tutorial to troubleshoot it. So if we type in –help, and here you have recursive, remove directories and their contents recursively. Let’s go ahead and do that because this will go into the folder, and remove everything within the folder, and the folder itself. So let’s just go ahead and type in rm -r placeToBe, press Enter, there you go. It has deleted all of it, and it is no longer there. The -f function, -f that I have used, is forced. It will not ask you any questions, it will delete the folder or file which can also be very dangerous. Ideally, you want to be asked for confirmation. In any case, as I said, I have deliberately left this in order to show you that even if you get stuck, don’t worry about it. I get stuck all of the time. If you don’t know what to type in, which 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 available to you. If you can’t figure it out from the help menu just type in man rm, and you can read pretty much everything there is to know about this command here. If you still can’t perform the task, if you can’t find anything useful here, then forums are your next best bet.
In any case, this was a brief introduction to some of the basic commands that we will use throughout the course. Please make sure that you know what each one of these commands does, at least the basic functions, and then later on we will get in-depth and do more advanced stuff. In any case, I bid you all farewell, and I hope to see you in the next tutorial.
The remainder of the tutorial videos can be found in this YouTube playlist:
You can also enroll in the course and download the videos for offline viewing:
If you find yourself needing assistance at any point throughout the tutorial series, feel free to enroll in The Complete Ethical Hacking Course Bundle for 1 on 1 help!
Hello everybody and welcome to this tutorial. Today, I will go over a few basic commands which you will need in order to follow this course through. These basic commands are used in order to navigate within the terminal, or through the file system, to figure out where you are at the moment, to copy things, move things, get listings of files, folders, see the contents, remove them, change the ownership of files, or change the modes of files.
So, first off, we have CD which is change directory. If I type in cd /home/ I am going to navigate over to my home directory. CD stands for change directory, as I said before, you are literally changing your working directory. If you type in cd .. you will always go one step back, so double dot is always the previous folder.
Next up we have LS. LS shows you the listing of the current folders contents, but you can also use ls /, for example home, and you get the listing of a specified folder as well. Typing LS in will give you the listing of the current folder, as opposed to typing LS and then a path to a folder which will give you a listing of a specified folder. In addition to that, you also have ls -l which will give you a long listing. It will tell you who the owners are, the size, the date, the type, the permissions, and so on and so forth. However, one of the more common usages of ls is -la to show the hidden files as well.
Next up is PWD, which prints the working directory, and you might find this a bit confusing, but slash in all Linux/UNIX-like systems simply refers to the root directory, to the beginning, to the root directory. I’m going to navigate over to home and then to PWD. You can see that I am in home at the moment. So print working directory does exactly what the name itself says, it prints your current working directory.
Next up, we have the CP command, which we already have used in order to copy VirtualBox guest additions from one place to another. Fairly simple. So if I, for example, go ahead and type in cp VBoxLinuxAdditions.run, and if I want to copy it somewhere, let’s say that I wish to copy it to var. I will delete this of course, and I will show you how to do that as well, but it’s fairly simple. So with cp you specify what you want to copy and where you want to copy it to. Keep in mind that you could have actually typed in here a folder, a full path to VirtualBoxguestadditions.run, you didn’t actually need to be in the home directory. The -v flag gives us this, so it tells us what was copied where. Let me show you what would happen if I didn’t have that, just like this. Nothing. There is no output. Now this is fairly simple when you have one very small file, but when you have a large file, let’s say 20 gigabytes or so, and you are copying it, you’re going have a blank screen below. Nothing will be happening. You will not be able to figure out where the copying process is going on, or whether it has actually crashed, bugged, or something of a kind. We’re passing the -v flag because the machine actually tells you what it is doing.
Now you might have noticed that all of these commands, more or less, have their own arguments which can be passed to them in order to modify what the command does. You can view a listing of these arguments, you do not need to memorize them all. So let’s use cp in this example. I’m going to type –help, so this is a universal way of getting help on a particular subject within the terminal. You type in the command, –help, press Enter, and you get a listing of possibilities. So I know it looks a bit messy and a bit difficult to see, but you don’t actually need to look at all of these things here. You can just scroll upwards and see all the arguments, they are listed clearly here. You have the argument here, and then you have an explanation of what the argument does. For the time being, you’re not going to be able to memorize all of these. But as you practice more and more, and as you start actually using these commands, you will begin to remember more and more. Basically, you’ll begin caching the information. Anyway, over here, in the upper part of this help menu, you’ll get usage. So in the usage you get the format, or the syntax, of the command. So with CP you pass an option, and then you specify your source and destination. Very simple. This is universal for all of the commands. You can always use the help menu.
In addition to the help menu, you also have the man pages. So if I type in man, and I’m going to use the command PWD, the man page on PWD gives me a ton of information. It gives you the name, it’s called synopsis here, but basically the syntax of the command. You get a full description of what the command does. Full description of the arguments. You even get the author who actually wrote it, some notes, copyright, etc. This is a very short man page because PWD is a very short command, and a very basic command. But, for example, if I was to type in man grep, you can see that the man page is a lot. Grep is a multi-purpose command which I will show to you in a moment, but I just wanted to show you the difference between a basic and a more complex command. Let me just go ahead and clear the screen.
Next up we have move, so MV. That will cause a folder to move. This is how you rename folders too, or files. So let’s just go ahead and navigate over to var where I have actually copied this file, ls, excellent! So if I say mv VBoxLinuxAdditions.run, I can either move it to a different folder, under a different name, or I can rename it within my current folder. So if I just type it in, I don’t know, let’s say RandomIsNotSoRandom. I’m just going to rename it to that and say .run. You can put whatever extension you want, of course it functions the same, but I’m just showing you the way of renaming a file. If I type ls again, you see that VBoxLinuxAdditions.run has been successfully renamed to RandomIsNotSoRandom.run. I can also move RandomIsNotSoRandom.run to my home directory. And if I type ls, and then specify a path to my home directory, and press enter, you can see that I have actually moved it here. But,
unlike the copy command, it doesn’t retain the original file, within the original folder. So, once you move it it will be deleted from the original folder. Also, be very careful with deleting files in Linux, because once you delete them from the terminal you will not be able to recover them. There are a few complex procedures that might give you a fraction of what you wanted to recover, but if you remove it from the terminal it’s very difficult. It’s not like Windows when you delete something. In Windows you can always recover a file, you basically didn’t even delete it. You just don’t see it. When you delete something on Linux it’s gone, permanently. So take great caution, take great care. So, I’ll just go ahead and clear the screen.
Next up we have CAT. Now cat gives us, well let me show you what cat does. Let’s navigate over to home, and let’s cat RandomIsNotSoRandom.run. It shows you the the entire contents of that file, whatever that might be. This content is not pretty at all, it is difficult to read like this. Let’s create another file, and I’m going to cat it. Nano is my favorite text editor from the terminal. You will need to learn how to use terminal text editors, because you don’t want to be switching back and forth between GUI text editors and working on something in terminal. It’s extremely time consuming, and plus here, you can actually edit things with root. However, if you are, for example, using another Linux distribution, most of the GUI text editors will not allow you to run them as root. You will receive an error message. So that can be a bit problematic. So just type in nano, and type in the name of the file that you wish to create. So, for example, I’m going to go ahead and type in test. This is going to be a test file, no need to give it any extensions. Now we are in the Nano text editor. So here I can, for example, write some text. Some random text goes here. Let’s just do that. Okay, so you have a wide variety of options down here. Well, maybe not a wide variety, but certainly a good amount. So this ^X simply means control + X. So if you press control + X you’re going to exit. Control + O is WriteOut, that’s basically save. Where Is is basically the way to search things, so control + V, and let’s say random, press enter, and there you go. It’s going to point to random. Cut text is also very nice because it allows you to remove large portions of text at a relatively fast rate. So if I press ctrl + K, it’s going to remove the current line where the cursor is, not what you have selected with your mouse. I will continue discussing basic terminal commands in the follow up tutorial. Until then, I bid you farewell.
The remainder of the tutorial videos can be found in this YouTube playlist:
You can also enroll in the course and download the videos for offline viewing:
If you want to become a Red Hat Certified System Administrator, you will LOVE this course! Whether you have no experience with Red Hat Linux or any other type of Linux operating system, you can count on this course to get you started with the basics and show you what to do all the way into the advanced material. You get to see immediately why Linux is worth learning and using. Learn the basics of CentOS and Red Hat Linux! Prepare and pass the RedHat certified system administrator (RHCSA) exam!
If you want to get started using Wireshark, you will LOVE this course. Learn to use Wireshark as a networking professional including troubleshooting, analysis, and protocol development. Use this course to speed up your learning with Wireshark with hands on tutorials showing you exactly what you can do in Wireshark founded on explanations of basic network terminology, installing Wireshark, and a review of the basic functions.
If you want to get started hacking you will LOVE The Complete Ethical Hacking Course: Beginner to Advanced! This complete course will take you from beginner to expert hacker. We will begin with the very basics showing you how to setup your environment, and move on to password cracking, WiFi hacking, Dos attacks, SQL injections, and much more! Enroll for free!