Commands that Unlock the Power of Your Terminal


Welcome to Linux and the great things you can accomplish at the command line. Becoming familiar with a few core commands goes a rather long way if you are new to Linux. This blog promises a guide that will help you get started with the most important commands that can help you utilise, manage, and fix what you are working on.
The Linux command line can be quite intimidating at first glance, but believe me, after you’ve used it for a little while, you’ll wonder how you’d ever lived without it. Whether you are navigating directories, viewing files, or creating new users or groups, these commands will quickly become your go-to commands.
With that being said, let’s unlock the ultimate power of Linux and control the command line like never before.
Linux Commands
Administrative User
An administrative user is also called a superuser, or a root user. This user has all the administrative rights and privileges in the Linux system. With a super user, there is no limitation to accessing the database or making changes in terms of administration, control, operations, etc.Example:
Type
sudo su -
in the terminalYou will be prompted to fill in your password. The password will be invisible, so you’ll just have to type and click the Enter button.
After you have logged in successfully, you will notice that your command line changed from
$
to#
, and also haveroot@
before your name. What this means is that you transitioned from being a substitute user to being a root user.
Package Management
Package management is the process of installing, updating, configuring, and removing software packages on a Linux system.
Let’s run
apt update
. What this command does is that it gives us a list of all the software available for an update, and gives us the number of software available for update.After that, run
apt upgrade
. This command upgrades all the software packages in your Linux system, and this takes approximately 40 minutes if you are a new Linux user on the Ubuntu distribution.When you see a prompt that states, ‘Do you want to continue? [Y/n]‘ click ‘y‘ and enter.
Create a Directory/Folder
Directories, which can also be referred to as folders, serve as an essential organizational structure for managing files efficiently. Benefits of a directory include: organizing files in a structured manner, access control for users, hierarchical system, backup and recovery, among others. Directories can be likened to folders in the file manager of a Windows operating system.
mkdir
<name of directory or folder>
cd
<name of directory or folder>“ command is used to change or open a directory.Create a text file
touch <file name>.txt
is a command used to create an empty file.
Moreover, we have discussed creating folders and entering those folders using the commandsmkdir
andcd
, respectively. So we created a few folders within a directory in the image below.
List Contents
There are a few commands that are commonly used to list content in the Linux system.
ls
- command is used to list content in a directory
ls -l
command is used to give detailed information such as permissions, owner, size and date in a long format.
ls -r
command list content in a reversed order.Open text editor
The text editor just as the name implies, is used to edit text files within the terminal so if you don’t have the tool, you need to install it using the commandapt install vim
to install it.
After the text editor tool has been successfully installed, we can open the text editor using the command vim <filename>.txt
.
Once we enter this command, the text editor file will open within the terminal.
Example:
Once this opens up, the next right thing to do is to click on the letter i
because you can do literally nothing till you click the insert button. Afterwards, you can type as much as you want in here.
To save your typed document in this text file, you need to:
click on the
esc
button on the top left corner of your keyboard.then insert
:wq
and click enter. That way you will save the text file and return to the terminal’s command interface.
Read-only Files
The cat command is used to view a text file, but it cannot be edited.
cat <filename>.txt
History Command
Thehistory
command shows a list of all the commands that have been previously ran in the terminal.Adding User
The commandsudo adduser <username>
is used to add another user to our virtual machine; however, this does not automatically grant the user root privileges on this machine, unless you specifically decide to do so.You will be prompted to add the root user’s password for this user to be added.
Note: On the Linux system, passwords are always invisible when typed and entered.
Afterwards, we can go ahead and set a password for the user.
While setting the password, we need to make sure that all our passwords are up to 8 small letters. If you get this prompt, you don’t have to worry, just repeat the password, and it will be set successfully.
Moreover, we will be prompted to add this new user’s details to the system to be able to add this new user to the system.
So this is the process of adding a new user to the system or an organization, as the case may be.
Switch User
We use thesu - <username>
command to switch users within the Linux system.Now this is the current user logged on the system at the moment. We are going to run the command
su - dora
so that our user can change from victor to dora. Kindly note that the name of the virtual machine was named ‘Victor‘ and the user was also named Victor, which is the reason we have Victor appearing twice on the system.However, before we can successfully log in as ‘dora‘, we will need to use Dora’s password to log in.
We have successfully switched users from Victor to Dora.
Apparently, Linux is case sensitive. In some cases, you may not be able to create a username that begins with a Capital letter. In some cases, you may need to alternate small letters.Fetch user details
The command line to fetch a user’s details isgetent passwd <username>
Examplegetent passwd dora
The result of the command that we ran shows Dora’s details, which include her full name, work number, and room number.
Lock and Unlock User
As a system administrator with root privileges, you can use these commands to lock a user’s account and also unlock a user’s account.
The command-line to lock a user’s account issudo usermod -L <username>
Example
Now we locked Dora’s account, denying the user from accessing the account, then we used the command line su - dora
to log in to Dora’s account, but it failed to log in, because it has been locked.
Now, let’s unlock the account.
We will run the command sudo usermod -U dora
to unlock Dora’s account.
After unlocking Dora’s account, we used the command line su - dora
to switch to Dora’s account, and now we have successfully logged into Dora’s account.
Delete User’s Account
To delete a user’s account from the system, runsudo userdel <username>
To delete a user’s account and email messages, run the commandsudo userdel -r <username>
Example:After we ran the command, it gave this response because this user does not have any saved email messages on the account.
Now we ran the “getent passwd dora” command to fetch details about this user, but it came back empty because this user no longer exists.Running Shell Scripts
What is a shell script?
A Shell script is a file that contains a sequence of shell commands that are executed in order.
Meanwhile, a shell is a program that provides a text-based interface for users to interact with the operating system.Popular shells include:
| Shell | Description | | --- | --- | | sh | Bourne Shell (original UNIX shell) | | bash | Bourne Again SHell (most common, Linux default) | | zsh | Z Shell (more advanced features) | | csh | C Shell (uses C-like syntax) | | fish | Friendly Interactive Shell (user-friendly design) |
Advantages of Using Shell Scripting
Shell scripting is used for the following:Automate repetitive tasks (backups, updates, deployments)
Configure system settings
Run multiple commands as a single program
Schedule jobs with tools like cron
Quickly test logic or prototypes
To run a shell script, you must start with Shebang, which is represented as
#!/bin/bash
.
Examples:
#!/bin/bash
read -p
“Enter your age: “age”if
[ $age -ge 28 ];then (the‘if’
command in this example states that if the age is greater than or equal to 28, then it should give the response in the first‘echo’
)echo
“How time flies! Should I hope to get invited to your wedding soon because you are long overdue for marriage?.”else
(in this example, the‘else’
command will propel the second‘echo’
to take effect if the age stated in the‘if’
command is lower than 28)echo
“I’ve known you to always be a brilliant one, so you should definitely focus on your studies.”fi
We vim into the text environment using
vim <filename>.sh
Then we save and exit using the
esc
botton, then:wq
to go back into the terminal.
To execute an actionable command within the terminal, we must change mode directly from the terminal using the commandsudo chmod u+x .sh
. Afterwards, we run the command./<filename>.sh
to execute it.
How to Create a Group
Basically, the commandsudo addgroup <group name>
is used to create groups in the Linux distro. However, we can also usesudo groupadd <group name>
to create a group. These two have slight differences in their functionalities.
The first command, which issudo addgroup <group name>
is the higher than the second command because this command is used to create an interactive group, unlike the second command,sudo groupadd <group name>
that is used to create a group that is just meant to follow commands and duties assigned to various users within that group.
Example:How to Add Users to a Group
The commandsudo usermod -aG <group name> <username>
is used to add a user to a group.
Example
So we will run the commandsudo usermod -aG cloud-develops rex
to add an already existing user with the username ‘rex’ to the group that was created earlier.Furthermore, to list all the groups in a system, we use the command
getent group
, orcat /etc/group
, to fetch details about a group, we use the commandgetent group <group name>
, to see groups that a user belong to, we use the comandgroups <username>
.
Conclusion
Mastering the Linux command line isn’t just about memorizing every single instruction rather, it cuts across building confidence through consistent practice, hence enabling the user to dot his ‘i’s and slash his ‘T’s. The simple commands we just explored are the building blocks of something much greater, which includes: control, customization, and creativity in your computing experience. Like learning a new language, fluency and mastery come from hands-on use. The terminal is more than just a black screen; it’s my canvas.
Subscribe to my newsletter
Read articles from Chiemerie Victor John directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
