Tuesday, July 23, 2019

Learn Basic Linux commands (kali linux)

Commands

The following sections illustrate the basic Linux commands.
The ls command
The ls command lists all of the files and directories that exist in the current working directory. So it's similar to the dir command in Windows machines; it just lists all of the files and directories that exist in the current directory:

ls

And, as we execute this command, the output for it lists all of the directories, such as DesktopDocumentsDownloads, and Music:

Let's run ls with some options. We going to use ls and then use -l, and that will show us more information about the files. It's basically the same command that we ran before, but, as we can see in the following screenshot, we now get more information. We can see the total entries that exist in the current working directory, and we can see the same directories that we saw before, but we can also see the dates that they were created or modified. We can see the user responsible for them, and its root use, and we can also see permissions:

We will learn more about permissions in the next chapters. Permissions specify which users can do what (read, write, execute). This is just an example of the ls command.
The man command
One of the most important commands, which is going to become handy to you in the future, is the man command. It stands for manual. The man command can be used to query and get the manual of any other command. For example, we just used the ls command to list all of the directories that exist in the current working directory:

man ls

After running this command, it will show us the manual for the ls command. And, as we can see, it's showing us that ls is used to list content, because it lists files and directories. We can also see that this command actually takes options, so it takes more options than just the ls command:

In the preceding screenshot, we can see the format of the options in Linux; it's either a letter abbreviation, or --, and you type in the full option. So, for example, the -- all option does not ignore entries starting with a dot. If we type in or press the Enter key, the manual will just keep going down so you can read more information. These are all of the options that you can do with the command. We can see, for example, that the -l uses a long listing format. To quit this command, we just type in q, so we're out of the manual.
The help command
Another really useful option is --help. We will use ls again, and do a --help command. Now, man and --help work on almost every command, so you can use man ls, or ls -help, and it will always show you the help or the manual page of the program. So, after we execute the preceding command, in the following screenshot, we can see the help page for using ls, and it tells us all of the options for the ls command:


Again, it's a - or a --, and we enter the option name as we did before. On top, it shows information about what the command does, and it gives the format of the command, so it should be used in this particular format: Usage: ls. We then enter the options, and then whether we want to do anything to the file. It's very similar to the man command; sometimes, programs will not have man, and they'll just have the help command.
If we have any command or any program that we are not sure how to use, we can always just type in man and the name of the command, or the name of the command and --help. Another useful exercise when dealing with the Terminal is that we can press the up and down arrows to go through the history of the command. So, we can switch between the man lsls -l, and ls --help commands through the up and down arrow
keys.
The Tab button
Another useful item is the Tab button on the keyboard. If we are typing a command, or if we are looking for a file and we are just not sure, we can use Tab button to autocomplete. For example, let's suppose that we want to type a filename. Let's first create a file; we just go to Places | Home, because right now, we are going to create a new file. Let's create a new folder, called test. Let's suppose that we are looking to do something with the test folder; the cd command can be used to change the working directory to another directory.
Let's suppose that we want to go into the test directory; we can use the command, and then find ourselves in the test directory: cd test/
Another useful command is pwd; it shows you the current working directory. Just execute it, and, as we can see, we're now in the root/test directory: pwd
Now, if we want to go back, we can just use cd, change the directory, and, instead of typing a directory name that we want to go to, we can just type cd ...
These were just basic commands, there are so many commands in Linux. Again, every program that we install on the system will have a Command Prompt version, and we can access that program through the Command Prompt. A lot of the programs that we're going to use will not even have a graphical interface, so we will have to use them through the Terminal. Again, don't be scared of that; we're going to go over it in the future.
Updating resources
Now that we know how to interact with the Terminal and Linux basics, we will just look at some final steps:
Updating the source list
Installing terminator
Installing required updates
Going to the Kali machine, the first thing that I want to show you is viewing the machine in full screen. Just go to View and then Full-screen, and that will automatically expand everything and put it in proper full screen.
Let's look at the package manager in Kali Linux. We can install programs using a command called apt-get. We usually type in apt-get, and then, if we want to install something, we type apt-get install, followed by the package name (the program name). Before we do any of that, we have to update the sources; the way this program works is through fetching a number of libraries. On a fresh installation, we want to update our sources, so we make sure that it has the latest sources for the libraries, and the latest available programs. We're just going to use apt-get update. This command will not update the system; it will only update the list of available programs that can be installed:

Now, everything has been updated, so we can go ahead and start installing programs. We
are going to look at an example of installing a useful Terminal application called terminator. The command is as follows: apt-get install terminator
Press Enter; now, it will ask us if we really want to install this. We will say yes, by typing and hitting Enter, and this will automatically download the application and install it for us:

Now, we can go ahead and try to use terminator. To do so, we will go to the
Applications on the menu bar toward the left and search terminator. We will right-click to add it to My Favorites, so it shows up in the dock. We are going to open it, it's just another Terminal application. We can increase the size of the text here, and actually run programs through the Terminal, using any of the commands we illustrated previously. The advantage of the Terminator is that we can split the screen and run multiple commands. If we right-click on the screen, we can split it horizontally, and we can have three different windows that can run three different commands or programs at the same time. So, this can be really handy; it can make your life much easier in the future.
One more command involves upgrading our system. In many cases, when we upgrade our system, we face issues such as broken libraries; some of our programs might not work when the libraries they depend on have updated, but the program itself has not. If we face issues, we can restore a previous snapshot; but generally, we just don't upgrade. If there's a new version of Kali, we just import that as another virtual machine, instead of upgrading the existing Kali version.
Now, if you want to upgrade your system, all you have to do is type in apt-get upgrade. If you press Enter, it will tell you that a large number of libraries and packages will be upgraded. If you hit Enter again, it will start downloading, installing, and configuring these packages as seen in the following screenshot:

It might ask you to configure a few things, so don't be too adventurous and try to change thingskeep them the way they are. Again, most of the time, we keep everything the same.