Linux Hand On
Linux Hand On
By Temitope Adeniyi G
The root directory (/) is the starting point of the Linux file system. It’s the parent of all files
and directories in the system.
It’s essential for the system to boot and operate because critical files and directories are
organized under it.
The root directory provides the framework to ensure that everything in Linux , whether it’s
user files, applications, or system logs , is stored in the right place.
The root directory is like a tree with branches. Every branch (file or directory) branches out
from the root.
Now lets navigate to the root directory, to do this, use ‘cd’ command which means change
directory, and (/ ) the sign for the root directory is (/)
Pwd is the command to check your present working directory, as you can see the output (/)
meaning I am in the root directory, don’t worry if this gets confusing at first, just hang on, you
will get it.
Now let’s check the directories under the root directory, remember, these directories are there
because they are essential for the system to boot and operate. To list this directory, we would
use the command (ls)
I want these files to be listed vertically rather than horizontally as seen above, I will use the
command (ls) with an option (-l) to give me (ls -l)
1. bin (symbolic link to usr/bin) : This directory contains essential binaries (commands)
needed for the system to function. These include basic commands like ls, cp, and cat. In
your system, it is linked to usr/bin for consistency. Think of it as a toolbox that holds
essential tools for both you and the system. No matter what happens, the system always
knows where to find these critical tools.
2. boot : This contains the files required to boot (start) the system, such as the Linux kernel
(vmlinuz) and bootloader configuration files (like GRUB). This is like the engine of a car.
Without it, the system cannot start.
3. dev : This directory contains device files that represent hardware like disks, USB drives, and
printers.
4. etc: The configuration files for the system and software are stored here like an
administrative office of the system, where all the rulebooks and policies (configs) are kept.
5. home: This is where personal files for each user are stored.
6. lib (symbolic link to usr/lib) : This contains shared libraries (like .so files) used by programs
in /bin and /sbin. Think of libraries in /lib as books that programs borrow to understand how
to work.
7. lost+found: This is a special directory created by the file system to store corrupted or
recovered files during system repairs. Like a lost-and-found box where recovered items are
stored until claimed.
8. media: This is where removable media like USB drives and CDs are mounted when
connected. This is like the parking lot for removable devices.
9. mnt: This is a temporary mount point for manually mounting file systems.
10. opt: This is used for installing optional or third-party software.
11. proc: This is a virtual directory that provides information about running processes and
system resources. For example, /proc/cpuinfo shows details about the CPU. This is the
control room where you can monitor the system’s internal workings.
12. root: This is the home directory for the root user (superuser), separate from regular users’
/homedirectories.
13. run: This directory contains runtime data for system processes, and temporary sockets.
This is like a real-time message board where processes leave notes for the system.
14. sbin (symbolic link to usr/sbin): This contains essential system binaries for
15. snap: This is specific to systems using Snap packages, a modern way of distributing
applications. It contains application files installed via Snap. Like an app store directory for
Snap-installed software.
16. srv: This directory is meant for data served by the system, such as web files for a web
server. Think of this as the public library where shared resources are made available.
17. sys: This is another virtual directory like /proc, but it focuses on exposing information about
hardware devices.
18. tmp: This directory is used for storing temporary files that applications create. It is usually
cleared upon reboot.
19. usr: This directory contains user-installed applications and libraries. Subdirectories like
/usr/bin and /usr/sbin house programs and system administration tools.
20. var: This directory contains files that are expected to grow, such as logs (/var/log), caches,
and spool files.
Now lets look at the content of the /etc directory for example, which is the directory that
contains the configuration files, remember the command to change directory is (cd) and the
command to list the directory is (ls) while (pwd) is the command to check the current directory
you are in.
Output: these are configuration files
As you can see, when we wanted to change the directory to /etc, we had to start with /, which is
the root directory — the starting point of the Linux file system. It’s like the trunk of a tree, and all
other directories branch out from it. On your own, you can explore the other directories under /
and read more about their purposes.
For now, I want to navigate to the home directory of the current user (ubuntu), which is like my
personal house where I can store anything and create my own files or directories. To do that, I
will run the command:
This navigates to my own home directory, no matter where it is located. The ~ symbol (tilde) is
shorthand for the current user’s home directory.
This is different from the /home directory under the root directory. For example, if I type:
It will take me to the /home directory, which is the parent directory for all users' home
directories on the system. Each user’s home directory is stored as a subdirectory under /home.
its showing ubuntu because it is the only user we have yet. Let’s go on with user ubuntu(default
user) later we will learn how to create more users.
Now I am in the home directory of ubuntu, this is where I will run all my commands and create
my files and folders.
Man pages are like instruction manuals or user guides for tools in a toolbox. Whenever you’re
unsure how a tool works, you can consult the manual for help.
man command
This displays the manual for the ls command, explaining what it does and its options.
This displays the manual for the pwd command, explaining what it does and its options.
Options and Arguments
Options are used to modify the behavior of a command. They typically start with a dash (-) and
are followed by a letter or word.
For example:
1. -l (long format): Displays detailed information about files and directories, such
as permissions, ownership, size, and modification date.
2. -a (all): Includes hidden files (files that start with a dot .) in the listing. Hidden
files are usually system files or configurations.
The ls -la command is like saying: "Show me everything in the room, including
what’s hidden, and give me detailed information about each item."
Arguments
Continuing with the coffee analogy, the argument is like specifying which coffee shop you want
your order from. for example: "Order coffee from Shop A (ls Temitope)." meaning list the
contents in the ‘Temitope’ directory
Ps: I created directory (Temitope), and then another directory (Gbadamosi) inside it for
context. Do not worry, you will learn how to create directories too, soon.
You can explore more commands with options and arguments using the man pages. I hope you
now understand the concepts of options and arguments. Hang on, You’ve got this!
Directory commands help you create, navigate, remove, and manipulate these directories oe
what you may understand as folders.
Displays the current directory you are in. It’s like asking, "Where am I right now?"
Basic listing
Used to navigate between directories. It’s like moving from one room to another in a house.
mkdir foldername
mkdir -p Tope/loves/food
What It Does:
cd ..
What It Does:
rmdir foldername
As you can see when i tried to remove Temitope’s directory, I got a message telling me the
directory is not empty, because you can only rmdir for an empty directory. Fred was empty, so
the rmdir worked and when I typed ls to list the content of the directory, Fred has been deleted.
rm -r foldername
Deletes a directory and all its contents (files and subdirectories). Now this will work for
Temitope’s folder that had contents in it.
To remove multiple directories use rm -r and list all the directories one after the other.
NOTE: Linux is case sensitive, Tope with capital letter T is different from tope with small letter t.
just thought to chip that in
Moves or renames a directory. It’s like moving a room to a different part of the house or
renaming it.
mv foldername1 foldername2
cp -r foldername1 foldername2
Copies a directory and its contents. It’s like making a duplicate of a room with all its items.
ls: Lists the contents of the current directory, showing directories enemy, folder1, and no files.
cp -r enemy friend: Copies the enemy directory (and its contents) into a new directory called
friend. -r option enables recursive copying, allowing you to copy directories and their contents.
Absolute Paths
An absolute path specifies the location of a file or directory starting from the root directory
(/).
It always begins with /. That is an absolute path starts from the root directory (/), so it gives
the complete location of a file or folder.
It’s like giving someone the full address to a house, starting from the main city:
Example: "City → Neighborhood → House."
Relative paths
specifies the location of a file or directory relative to your current directory.
It does not start with /. A relative path starts from your current location. It’s like giving
directions based on where you currently are: Example: “when you get to enemy, turn left, then
walk two houses down, you will topsy ." notice it is relative to home/ubuntu my current directory
then ran
Command: cd enemy/topsy
What I Did:
Navigated into the topsy directory inside enemy.
Why:
enemy/topsy is a relative path from /home/ubuntu, allowing me to specify a location
without using an absolute path.
Command: pwd
What I Did:
Checked your current directory, which displayed /home/ubuntu/enemy/topsy.
Why:
To confirm that you successfully navigated to the topsy directory.
Key Differences
One important thing to note about absolute paths is that you can run them from anywhere in
the file system, regardless of your current directory. As long as you know the full path, it will take
you directly to the desired location.
For relative paths, you must be in the correct starting directory for the path to work. Relative
paths depend on your current location in the file system.
File commands in Linux are used to create, view, edit, move, copy, delete, and manipulate
files.
touch filename
vi filename
Cat filename
As you can see from the above, the cat command displayed the content of that file i just wrote in
wc filename
7- showing 7 words
Purpose: Searches for a specific word or phrase in a file and displays matching lines.
Remember linux is case sensitive when i did grep “devops” file1.txt, i didn’t get any output
because it didn’t find that pattern, but when i did a case-Insensitive search using the option (-i),
it gave me the result regardless of whether it is a small or capital letter.
cp filename
Redirection allows you to control where the output of a command goes (e.g., to a file instead
of the screen) or where the input of a command comes from (e.g., from a file instead of
typing).
‘Echo’ command
What Is the echo Command?
1. Output Redirection
Command 1: > greater than sign (Redirect Output to a File)
The command echo “Temitope is a pharmacist turned devops and devsecops enginneer”
redirected the output of the echo command which should normally display the screen into
file1.txt and overwrote existing content. “Temitope is a Devops and Devsecops enginneer”
Redirects the output of a command to a file, appending (adding ) to the file if it exists. it
does not overwrite the existing content unlike command (>)
2. Input Redirection
Command 1: < (Redirect Input from a File
Redirects input from one file and sends the output to another.
The command above redirected the output of cat < file1.txt which is to read and display the
content of file1.txt, into another file file2.txt
4. Error Redirection
Command: 2> (Redirect Error Output to a File)
Redirects error messages (stderr) to a file. Standard error (stderr) is the output you get
when the shell encounters an error, and it's usually displayed on the screen. For example, if
I ask the shell to list the contents of a non-existent file, I will get an error message - No such
file or directory
I am asking it to list the nofile with the command (ls nofile), which does not exist. Instead of
having the output display on my screen, I can redirect it into another file for analysis or audit
later.
Saves the error message to error.log and also creates error.log file is it’s not existing.
5. Pipes (|)
Command: | (Pipe Output to Another Command)
ls | grep file
ls -l | grep file basically ls pipe grep file, the pipe send the ouput as input to the
grep command, grep filters only for files containing the word ‘file’
Links in Linux are pointers or shortcuts to files and directories. They allow you to reference a
file or directory without duplicating its contents. Think of a link as a shortcut icon on your
desktop that points to an actual file or folder somewhere else. Clicking the shortcut takes
you to the original file.
Types of Links
1. Hard Link
a. A hard link is a direct reference to the physical data of a file on disk.
b. Even if the original file is deleted, the hard link still holds the data.
2. Soft Link (Symbolic Link)
A soft link is a shortcut to the original file or directory.
If the original file is deleted, the soft link becomes broken.
Commands:
1 Create a file:
Notice the same file size and link count for original.txt and hardlink.txt.
Permissions in Linux
What Are Permissions in Linux?
Linux permissions determine who can access a file or directory and what actions they can
perform.
For every file and directory, permissions are defined for three types of users:
1. Owner: The user who created the file or directory.
2. Group: A collection of users who share access.
3. Others: Everyone else on the system.
Think of permissions like keys to a house:
The owner has the master key.
The group has limited access to shared areas.
Others may only see the house from outside but can’t enter.
let’s take errorlogs.txt (no 2 on the list ) file for example, the permissions are
r - read
w- write
x- execute
Practical Tasks
Task 1
Create a file
The default permission on this newly created file is rw (read and write) for owner, rw (read and
write) for group and R(execute for others)
in numerical value, this permission will be 664 that is (r-4 + w-2 = 6) for owner, (r-4 + w+2 = 6) for
owner, and (R-4) for others, that gives us 664 permission.
Now to modify this permission using letters, we will use chmod command
This command modifies the permissions of the file linuxclass.txt for the owner, group, and
others. Each part of the command specifies different permissions for these categories.
chmod
u=rwx
g+x
o=
linuxclass.txt
if you remember ugo, but you can just use numbers, they are easier
chmod
The number 777 sets read (r), write (w), and execute (x) permissions for:
Owner (u) → Full permissions (rwx).
Group (g) → Full permissions (rwx).
Others (o) → Full permissions (rwx).
linuxclass.txt
Numeric Representation:
What Happens:
There are other commands like chown, chgrp- please go and read more
Displays a real-time summary of system performance, including CPU usage, memory usage,
and running processes.
There are other commands as well, like ps -ef, df, proc e.t.c,
please read up and explore.
sudo (Superuser Do): A command that allows a regular user to run administrative tasks
(commands requiring root privileges).
It temporarily elevates the user’s permissions to execute restricted operations, such as
managing users or installing software.
Think of sudo as a keycard that lets you temporarily access restricted areas in a building.
The adduser command creates a new user with a home directory and prompts for a
password.
adduser username
Step 1: Attempt to Add a User Without Sudo
adduser gbadamosi
Result:
The command fails with the error: fatal: Only root may add a user or group to the system.
Why? Adding a user is an administrative task, so we need root privileges (via sudo).
The command cat /etc/passwd displays all the users on the system. Each line in the file
represents a user account and contains several fields separated by colons (:). Let’s focus on the
Gbadamosi user entry and break it down field by field.
Breakdown of Gbadamosi's Entry
1. Username (gbadamosi)
This is the login name for the user. When I switch to this user or log in, I use gbadamosi.
The x indicates that the encrypted password is stored in a separate file called /etc/shadow,
which is more secure than storing passwords directly in /etc/passwd.
This optional field stores additional information about the user in the following format:
mathematica
CopyEdit
Full Name,Room Number,Work Phone,Home Phone,Other
For Gbadamosi:
Full Name: Gbadamosi Adeniyi Temitope
Room Number: 2
Work Phone: 123456789
Home Phone: 7888888
Other: 8888888
The user’s personal directory where their files, configurations, and settings are stored.
When Gbadamosi logs in, this is the default directory.
Package Management
What Is Package Management?
Package managers are tools that automate the process of installing, upgrading, configuring,
and removing software on Linux systems. it is like an app store for Linux, but everything
runs in the terminal.
Package management simplifies the installation, updating, and removal of software in Linux. It
eliminates the need to manually download and configure software from the internet.
Key Concepts:
1. Repositories:
Centralized locations where software packages are stored.
The package manager fetches software from these repositories.
2. APT (Advanced Package Tool):
The package manager for Debian-based systems (like Ubuntu).
Used to install, update, and manage software packages.
3. Commands:
install: Installs a package.
update: Updates the list of available packages.
upgrade: Upgrades installed packages to newer versions.
for example, let’s say we need maven, what is maven? Apache Maven is a build automation
tool primarily used for Java-based projects. It manages:
Now we needed maven and we checked for it using command maven --version or mvn --version,
it says not found because maven is not yet installed.
The error Command 'maven' not found indicates that Maven is not installed on the system.
The system suggests using a package manager (sudo apt install) to install it.
What It Does: Refreshes the list of available software in your system’s repositories.
Press y to continue, However, if i had done sudo apt install maven -y it would have installed it
automatically without asking any questions.
After the installation using our package manager (sudo apt install), we see maven successfully
installed.
The linux distro I chose for this project was Ubuntu, hence the reason we used sudo apt install
Final Notes
Phew! It’s been a ride! This guide is an introduction (an incredibly detailed one) to get you
started on grasping Linux commands, a vital skill for DevOps and DevSecOps.
Remember, this is just the beginning. There are so many more commands and concepts waiting
for you to explore. Research, practice, and keep building on what you’ve learned.
As I always say: people can only give you 50% at best, but you have to bring your own 50% to
make it 100%.
If you have questions or need clarification, feel free to reach out to me on LinkedIn at Temitope
Adeniyi Gbadamosi.
You’ve got this! Relax, practice, give yourself some time, and allow plenty of grace as you learn.
Wishing you all the best on your journey!