Hello, friends and welcome to the advanced Linux commands tutorial. In this tutorial, I am going to discuss some of the widely used Linux commands for advanced users.
If you are a complete newbie to the Linux world then please consider checking
- Linux Command Line Basics
- Linux Commands For Intermediate Users.
- Hacking Tutorial For Beginners
- 5 Step Hacking Process
If you already know the basics of the Linux command line, then you are good to go.
So let’s begin.
Advanced Linux Commands Level Your Way Up
Adding a user to your Linux machine is not a difficult task. If you are running Linux on your PC you can easily add a user using the GUI (Graphical User Interface).
But when you’re are operating Linux on a server you’ll be not provided with the convenient GUI interface. You have to use the CLI (Command Line Interface) to perform all of your tasks.
Now, to add a user to your Linux machine you have to run the command:
Eg: adduser testuser
When you hit enter you’ll be asked to supply a password for your newly created user. Enter your desired password and hit enter.
After that, you’ll be asked to fill details such as Full Name of the user and some other information. You can either fill this information or just hit enter and skip filling these.
Then you’ll be prompted a question Is the information correct? [Y/n]
Enter y and hit enter if you are satisfied with the information you filled or n to again fill the information for the user.
Deleting a user
For deleting a user you can simply use the command: deluser <user_name>
Eg: deluser testuser
The sudo command is used to allow users to run commands as root user which normally, they won’t be able to run.
When you create a new user it does not have access to use the sudo command. You need to add the user to the sudoers file or simply assign the group sudo to the user in order to give access to sudo command.
addgroup <user_name> sudo
Eg: addgroup testuser sudo
The su command is used to switch to a different user’s account. You can use this command with the username of another user to log in with that user’s session.
This command comes in very handy and saves a lot of time as you don’t need to log off and then login as another user to access his account.
Syntax: su <username>
For eg: su testuser
You can now see that the prompt has changed and now you can execute commands on the user’s account.
Any changes you make in the another user’s session will be permanent. To exit anytime from the other user’s session just type exit and hit enter.
And now you can see that we are back to our prompt.
The environment variables are the variable which stores various kind of information about the shell environment.
In other words, the variables which are used to define the environment of the shell are known as environment variables. These variables are interpreted every time you launch the terminal.
To list all the environment variables simply run the command printenv.
To create your own environment variable you can simply use the export command.
For eg: export TEST=1
You may have noticed that these variables are in capital letters. This is done by convention. You can name an environment variable with lowercase letters also.
You can also look at the value of an environment variable using echo command, like echo $PATH.
So let’s take a look at some of the environment variables:
|HOME||This variable stores the location/path of the home directory of the current user|
|SHELL||this variable stores the path to the shell of the current user.|
|PATH||This variable store different paths where the shell looks for the executable files of the particular command.|
Whenever you run a command the shell looks in directories listed in the PATH environment variable for the executable program written for that specific command.
Grep stands for global regular expression print. This is a utility which is used to search text-based files for a certain kind of pattern.
Syntax: grep [switches] <pattern> <file_name>
You can either supply the file to the grep command or can simply pipe the output of another command to it.
So let’s take a look at the example:
Suppose we have a file named check.txt which have following content written on it
Now we want to extract only those line where the word os occurs then we can do something like this:
grep ‘os’ check.txt
This will give us the following output
This was just a simple example to give you an overview of the grep command.
We can use different kinds of metacharacters in our pattern and do pretty complex pattern matching.
Two basic and simple metacharacters are caret ^ and dollar $ symbol.
Here’s is an example of using caret ^ symbol in pattern matching
grep ‘^os’ check.txt
The caret symbol specifies to match only those lines which BEGIN with word os.
grep ‘os$’ check.txt
The dollar symbol specifies to match only that line which ENDS with the word os.
The metacharacters in grep are:
|^||matches at the beginning|
|$||matches at the end|
|.||match any character|
|\||matches whatever follows it (allows metacharacters to be matched)|
|[ ]||match only one within the set like this character or this character or this character|
eg: [ABC]; this works like A or B or C; this will also match string ABC.
|^|| at the beginning of a bracketed expression negates the expression|
eg: [^ABC]; not an A or B or C
This command stands for process and it will list the processes which are running in the current shell session.
For eg: ps
|PID||This stands for Process ID. It is the unique number which is assigned to every process.|
|TTY||This stands for Terminal Type. Earlier it was called TeleType. This tells us the name of the terminal in which the user is working.|
|TIME||It shows the time it took for the CPU to run a command.|
|CMD||This stands for command and it shows the name of the command that launched the process.|
If you want to see all the processes which are currently running in your system you can use ps –e
Try running the following command in your terminal: Sleep 10
What you’ll see is that the prompt will be inaccessible for 10 seconds.
Now run the same command in the background. To run any process in the background simply add the ampersand & symbol at the end of it.
Now this will run the sleep command in the background. To check the running processes use the command ps. You can see the process sleep.
In order to terminate this process, you need to use the kill command.
Use the kill command and give it the process id of the process which you want to kill.
In my case, it is 3787
So I will run this command: Kill 3787
Sometimes a process won’t kill even if you run the kill command. In order to terminal such processes, you need to specify a signal with the kill command.
You can run kill -9 <process_id> to kill such kind of processes.
To list all the signals available with the kill command run kill –l.
The top command will give a real-time overview of the processes running in your system.
Rundown: Advanced Linux Commands Level Your Way Up
So that was an overview of some of the advanced Linux commands. There is a lot more than you can discover just by using these commands.
- Create Your Own Website On Deep Web!
- How To Set ASCII Text Art In Terminal
- How To Install Tor On Kali Linux
- Setup Proxychains In Kali Linux To Stay Anonymous
- Google Chrome Game Hack
You can always look at the man page of command if you need to know more about it. With that said if you faced any problem while executing these commands please let me know in the comment section below.
If you have any query suggestion or topic that you want to me write about, please feel free to contact me. Keep visiting Hackingpress for more tutorials and guides like this.