Come Let’s Walk Through Linux Together


Linux was built by and named after Linus Torvalds. Linux is an open-source operating system for servers, computers, mainframes, mobile systems, and embedded systems. The full form of LINUX is Lovable Intellect Not Using XP
Linux is scalable, stable, safe and serves wide users in the community. For almost any imaginable file type, Linux is compatible and, therefore, can operate on a broad range of devices. Linux is a multiprogram operating system that ensures that multiple users with different access rights can use the same tool and many applications can run on it simultaneously.
Features of LINUX
A few characteristics of LINUX are listed below.
Linux can operate on various types of hardware, so Linux is transportable.
Linux is open-source, so it is open to use, and developers may also try to improve the Linux operating system’s features.
It’s a multi-use operating system so multiple people may use the model.
Linux is secure, as it offers secure passwords and data encryption.
Linux is multi-programming, as multiple programs can be run simultaneously.
Benefits of LINUX
An extensive range of file formats is compatible with Linux.
Linux is cost-free, so it is conveniently downloadable and used by people.
Every day it is changing as people can make improvements to the Linux system.
Since they are relatively safe, the Linux system hardly crashes.
Linux may not gather any user information, so the privacy of information is guaranteed.
SOME BASIC COMMANDS IN LINUX
(1) sudo su command
sudo stand for superuser do or sudo enables non-root users to execute administrative commands. Simply add it at the beginning
su means substitute user or switch user. This command lets you switch to another user in the Terminal session
using sudo su allow you to enter as a root user enjoying the administrative privilege.
Example:
Type sudo su in the terminal and press entre. Enter your password will prompt up
Enter your user password when prompted. Note your password will be invisible as you type it
After successful authentication, your command prompt will change (typically from $ to #), indicating that you are now operating as the root user as seen in the Image below
(2) apt update and apt upgrade
This command is use to ensure that your software package is up to date, apt update will update while apt upgrade will upgrade your software package
Example
Type apt update on your terminal to update system package lists for upgrades
- Type apt upgrade to install the newest versions of all packages currently installed on the system
(3) mkdir command
This command is use to create directory. it allows you to create fresh directories in the terminal itself. The default syntax is mkdir <directory name> and the new directory will be created.
For example, if you want to create a directory as “Hiladex” then type mkdir Hiladex in the terminal and press enter
directory that was created is Hiladex, to check it use ls -l as show below
(4a) cd command
The cd command is used to navigate between folders. It requires either the full path or the folder name, depending on your current working directory. If you run this command without any options, it will take you to your home folder.
To run it type cd <name of the folder>
the folder her is Hiladex that was created as a directory, you can notice the the # sign is now infront of Hiladex this shows that we’re now inside that folder
(4b) cd .. command
This command is use to come out of folder. To use just run cd .. in the terminal as shown below
if you notice from this picture after we’ve run the command Hiladex is not there again, this shows that we’re out of the folder.
(5) ls and ls -l command
The ls command is commonly used to open files and directories in the working directory. This command is one of the many often-used Linux commands.
This command will provide us the output with all the details about the files and the directories in the current working directory. There is a lot of flexibility offered by this command in terms of displaying data in the output.
To run it just type ls in the terminal and press enter
for ls -l see the result below
(6) touch command
touch command is use to creates an empty file it can be run in the terminal in the format below touch <file name>
from the picture above empty file created is E-book
(7) vim / vi command
Vim is use to access text editor, first we have to install vim / vi in other for us to use it
sudo apt install vim run this command on the terminal and press enter. NOTE: You can either use vi or vim as a text editor
vim is a highly popular and powerful text editor commonly used on Linux systems, especially by developers and system administrators. It's an enhanced version of the Vi editor, offering features like syntax highlighting, multi-level undo, multiple windows and buffers, and command line editing.
Starting Vim: To open a file in Vim, use the command vim <filename> in the terminal.
Entering Insert Mode: Press i to switch to insert mode and start typing.
Exiting Insert Mode: Press the Esc key to return to Normal mode.
Saving and Quitting: Use the colon : to enter Last-line mode, then type wq and press Enter to save and quit.
from the picture filename in which we insert our text is E-book we created
(8) history command
history command shows a list of the commands entered since you started the session.
The history command helps you keep track of the commands you’ve executed in the terminal session, which can be useful for recalling complex command sequences or troubleshooting issues.
Running the history command without options displays the list of commands used since the start of the terminal session just type history in the terminal in press enter
(9) cat command
The cat command is use when you want to see the contents of a particular file. Its read only command
To use run cat <filename.txt>
from the picture above, file name is E-book where we insert text at at command no 8
(10) sudo adduser command
The sudo adduser command is used to create a new user account in Linux. It's a user-friendly command that simplifies the process by prompting for user information and automatically configuring settings like the home directory and default shell. You need to use sudo because creating a user is a privileged operation requiring root access.
Type sudo adduser <username>, replacing username with the desired username.
the system will then ask you for the following information:
Password: Enter a secure password for the new user and confirm it.
from the picture above, new user name created is fiayomi, after that we put password for the user and add all the information of the user.
(11) sudo userdel
This command is use to delete a user account created
To delete a user using the userdel command, open a terminal and type: sudo userdel <username> Replace “username” with the actual username you want to remove
in the picture above the username deleted is fisayomi, after deleting the user we try to run getent passwd fisayomi to see profile of the user but nothing show up which to tell us that the username does not exist
(12) getent passwd command
The getent passwd command in Linux is used to retrieve and display user account information from various configured databases.
Usage:
Listing all users: getent passwd will display all user accounts and their details.
Listing a specific user: getent passwd <username> will show details for the specified user.
from the picture above username is fisayomi and we can see all the information about the user
(13) su - command
The su - command in Linux allows a user to switch to another user account, typically the root account, and also starts a new login shell with the target user's environment. It's used for tasks requiring elevated privileges or switching to a different user context.
Examples:
su - (without a username): Switches to the root user and loads the root user's environment.
su - <username>: Switches to the specified user and loads their environment.
(14) sudo usermod -L / sudo usermod -U command
This command is use to lock a user account this will keep user out of accessing the account until it is unlocked
To use it
sudo usermod -L <username>
And to unlock the lock user account use:
sudo usermod -U <username>
(15) sudo groupadd command
The sudo groupadd command in Linux is used to create a new user group with root privileges. It requires the sudo prefix because modifying system groups requires administrative rights. The basic syntax is sudo groupadd <group_name>, where <group_name> is the desired name for the new group.
the name of the group created above is communication
(16) sudo usermod -aG command
This command is use to add use to the group to do this just input in the terminal sudo usermod -aG <groupname> <username >
The group name will be the name of group where you want to add user and user name will be the name of user that you want to add to the group as shown below
from the picture above user fisayomi and adeolu was added to communication group
(17a) getent group <groupname> command
This is to check the list of users in a group to do this enter in the termina
getent group <groupname> group name here will be the name of that group you want check using communication as the groupname
from the picture above we can see that user fisayomi and adeolu are in communication group
(17b) groups <username> command
this command is use to see the group a user belong to, using username fisayomi run the command: groups fisayomi
from the picture we can see that the user is in communication group
(18) sudo groupdel command
This command is use remove a group in Linux, use the groupdel command with sudo to gain the necessary privileges. The command sudo groupdel <groupname> will remove the specified group from the system. Ensure you are root or have sudo privileges to use this command.
from the picture above after deleting the group we try to check users in the group and ls -l and nothing is coming out from communication again.
(19) sudo chmod u+x <filename> command
The command sudo chmod u+x <filename> in Linux modifies the permissions of a file, specifically adding execute permissions for the file's owner (user). The sudo part gives the command elevated privileges, allowing it to modify files that the user might not normally have access to. chmod is the command for changing file permissions, u+x specifies that the execute permission (x) should be added to the owner of the file (u), and <filename> is the name of the file you want to modify.
Here's a breakdown:
sudo: This command executes the following command with superuser (root) privileges, allowing for changes to system files or files owned by other users.
chmod: This is the core command for changing file modes (permissions).
u: This refers to the "user," which is the owner of the file.
+: This indicates that a permission is being added.
x: This represents the "execute" permission.
<filename>: This is the name of the file whose permissions you're modifying.
(20) sudo chmod g+x <groupname> command
The command sudo chmod g+x in Linux is used to grant execute permissions to the group associated with a file or directory. sudo is used to execute the command with root privileges, allowing modification of permissions even if the current user is not the owner or part of the group.
g+x: This part specifies the permissions to modify. g refers to the group, and +x adds the execute permission.
g+x: essentially means "add execute permission to the group”
To run this type: sudo chmod g+x <groupname> and press enter
study the image below:
r ~read
w~ write
x~ execution
d~ directory
(21) sudo chown <username> <filename> command
chown
Purpose: Change file ownership
The “chown” command in Linux helps you change the ownership of files and directories. It allows users to transfer ownership of a file or directory to a different user or group. This command is particularly useful for managing file permissions and ensuring that the appropriate users have control over specific files and directories.
Example: sudo chown <username> <filename>
from the picture above we switch E-book file adeolu
It can also be use to change group ownership too, the command will change to: sudo chgrp
Shell scripting
Shell scripting involves writing sequences of commands and instructions designed to be executed by a Unix/Linux shell, which acts as a command-line interpreter. These scripts are essentially programs that automate various tasks and operations within the operating system.
Key aspects of shell scripting:
- Automation:
Shell scripts are primarily used to automate repetitive or complex system administration tasks, such as file manipulation, backups, log analysis, system monitoring, and software installations.
- Command-line execution:
Scripts are executed by the shell, which interprets each line as a command or instruction to be performed.
- Shebang line:
Shell scripts typically begin with a "shebang" line (e.g., #!/bin/bash) that specifies the interpreter to be used for executing the script.
- Variables and Control Flow:
Shell scripts support variables to store data, and control flow structures like if/else statements, for loops, and while loops for conditional execution and iteration.
- Portability:
Shell scripts are generally portable across different Unix-like systems (Linux, macOS, etc.) and can even be run on Windows using tools like Git Bash or the Windows Subsystem for Linux (WSL).
- Integration:
Scripts can interact with other programs, utilities, and even external systems or services, enabling complex workflows and integrations.
- Debugging:
Most shells provide built-in debugging features and error reporting tools to help identify and resolve issues within scripts.
Common uses of shell scripting:
System administration and automation, Software development and build processes, Data processing and manipulation, Deployment and configuration management, and Creating custom tools and utilities.
Common commands
1. vim <filename.sh>
this command is use to enter text editor in bash shell. File name is the name of the file we want to create.
Starting Vim: To open a file in Vim, use the command vim <filename.sh> in the terminal.
from the picture above file af.sh was created
Entering Insert Mode: Press i to switch to insert mode and start typing.
Exiting Insert Mode: Press the Esc key to return to Normal mode after once you are done with typing.
Saving and Quitting: Use the colon : to enter Last-line mode, then type wq and press enter to save and quit
2. #!/bin/bash
This command is to tell system to use bash shell
3. read -p
this command is use to ask question
we’ve a statement of asking question response here from the picture above
4. sudo chmod u+x <filename>
this command grant execution permission to a file
filename from the picture above is af.sh.to run or execute a file we have to grant that file execution permission
5. ./filename
This command is use to run execution for text file. File name is the name of the file created af.sh below is the result of the execution
once you type your name below is the response
from the picture above Adeyemo Israel is the name
Subscribe to my newsletter
Read articles from Israel Adeyemo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
