Objective
In Part 1 of this series “Linux 101 : Learn Linux CLI the Right Way” we take a look at the most powerful tool within the Linux operating system which is the “Terminal” and we did run few basic commands so you can get a foundational understanding of what the terminal is and what commands look like!
As the saying goes, with great power comes great responsibility, So in order to maximize your control over Linux OS, It's essential to have a solid grasp of what happens when you enter your commands. In the upcoming sections, we will take a deeper look into the mechanics behind running your commands and how they are structured, ensuring you can utilize them effectively.
If you have some prior Linux experience but feel that something is lacking in your comprehension, it's likely you'll want to gain clarity on the topics we will discuss. You will learn about the distinctions between commands, the terminal, and the shell, leading to a more profound understanding of what occurs when you use the terminal and execute your commands.
you will learn the difference between the commands, the terminal and the shell.
you will have much deeper understanding of what’s going on when you use the terminal and execute your commands
You will have full understanding of how commands are structured within Linux
Commands vs Shell
Simply, commands are just text but when you press enter the meaning of that text is translated by computer program called the “shell”
So let’s take an example, When you see the word "RASPBERRIES" written somewhere, at the physical level it's just a collection of letters arranged in a specific pattern. If you don't understand English, these characters hold no meaning to you, they're just letters. However, if you can read English, your brain processes these letters, recognizes the pattern, and translates it into the concept of the sweet red fruit with its distinctive appearance and taste as shown on the right side of the figure.
So there is a process in the middle between interpreting that word into specific meaning and that is the job of the shell.
To make the concept clearer, let’s take another example, let’s say you took the word “Gift” and you read that word using English language and the meaning that come out might be the idea of giving someone a birthday present
Now, instead of interpreting the word "Gift" using an "English shell" as show above, let’s imagine reading it through a "German shell" In German, "Gift" means poison, which is significantly different from its meaning in English.
You can see here that the text (Gift) is exactly the same but the meaning that comes out is different depending on the shell that translated it.
Now we understand the difference between a “command” vs “shell”, what about the terminal? Well the terminal is nothing more than a window to the shell
so if I ask you, how would you type commands into the shell without opening a terminal, you couldn’t right? and that’s exactly what “Terminal” is, it’s like middle piece between typing commands and submitting them to the shell.
Types of Shells
Just like there are different human languages that can translate the same word differently as shown in the above example, there are different types of shells that can translate your commands in Linux operating systems. Fortunately, there is one type of shell which is the most common type - the Bash shell. If you've ever heard the term "Bash scripting," this simply means writing scripts that can be read by the Bash shell, which most Linux distributions use as their default shell nowadays.
Here is a list of the most common shells:
Bash (Bourne Again SHell) - The most common default shell on Linux
Zsh (Z Shell) - Enhanced shell with improved features, now default on macOS
Fish (Friendly Interactive SHell) - User-friendly shell with robust auto-suggestions
Ksh (Korn Shell) - Combines features from many shells
Csh (C Shell) - Shell with C-like syntax
Dash - Lightweight shell optimized for script execution
the default shell in Ubuntu remains Bash (Bourne Again SHell). This has been consistent across recent Ubuntu releases, While some other Linux distributions have switched to alternatives like Zsh (as macOS did), Ubuntu has maintained Bash as its default shell for consistency and compatibility reasons and this is the type of shell we will use in this series of posts.
To check which shell you're currently using, you can use this command “echo $SHELL”This will display the path to your current shell (e.g., /bin/bash
for Bash) :
root@vps004:~# echo $SHELL
/bin/bash
alternatively you can use the special parameter $0 as follow:
root@vps004:~# echo $0
-bash
To displays information about your current shell process, including its name
root@vps004:~# ps -p $$
PID TTY TIME CMD
6816 pts/0 00:00:00 bash
and finally for more detailed shell version information :
root@vps004:~# $SHELL --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
root@vps004:~#
to summarize:
Commands are just text you type in the terminal
Commands are translated by program called the shell
Different shells can translate the same text (commands) in different ways
Most Linux distributions use the bash shell, and this will be our default shell
Terminal is the window to the shell, that allow you type commands
Commands are case-sensitive always
Linux Commands Structure
One reason that Linux is amazing, is that the commands you type ALL follow a similar type of structure in the way you type them, By understanding the structure you will be able to transition simply from memorizing commands to actually understand the common language that all Linux commands use and this will give you massive boost in your learning process.
Every Command is little computer program
the first thing you need to know is that all commands are little computer programs installed somewhere in your Linux OS. For example in part 1 we take a look at few commands like “echo” , “cal” , “date” , “history” and “clear”. all these are tiny computer programs.
The General command structure is that, you start with the command/program name (echo , cal, date, etc..), then you provide some options to customize it’s behavior, then you give the command some input to actually operate on.
CommandName + Options + Inputs
CommandName: This let’s the shell knows what program you want to run, and search for that program in something called “Shell’s Path” which is simply list of folders that contains these tiny computer programs also known as commands.
you can actually see your shell’s path by typing
:
root@vps004:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
the output is simple, these are different folders paths each separated by colon:
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin
The shell will start will start at the very left of the list of paths it has, and will look inside that folder for the program name (CommandName) you typed like the “date” program as an example, and if it did not find that program “date” it will move to the next folder, until it got to the last folder which is (/snap/bin)
if the shell search all the folders and it did not find your command (program) it will gives you some error like : Command Not Found
root@vps004:~# bla
Command 'bla' not found
This means that the shell searches all the paths listed above, and it did not find the command (program) called “bla”
Let’s imagine that “bla” is real command, and it’s located into tow folders, (/usr/local/sbin) & (/usr/games)
which one do you think it’s going to run when you type the command?
It will only run the version located in here (/usr/local/sbin) because shell always start from the far left and once the program is located it will be run, so it will never make it to the (/usr/games
) folder because the shell was able to find our imaginary program/command “bla” in the first folder of the list of paths, thus ignoring the rest.
Now if you have a command in your mind and you want to know in which folder this command (program) is stored, you can use the “which” command to know that:
root@vps004:~# which cal
/usr/bin/cal
From the output above, we can see that the “cal” Command/Program is located at the following path (/usr/bin/cal)
and that’s how the shell finds your command.
Inputs
Not all Commands require input, but most of them do and these inputs can have fancy name called operands (because commands operate on the input = operand)
to give a command some form of input, you simply type space after the CommandName and provide your input
let’s take the basic “cal” command as an example, we can just type cal and get the calendar for the current month:
root@vps004:~# cal
April 2025
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
or we can give the command single input, like “cal 2020” to get the calendar for 2020:
root@vps004:~# cal 2020
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31
we can also provide more than one input, for example let’s give our “cal” commands two inputs this time to display “December 2025” calendar:
root@vps004:~# cal December 2025
December 2025
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
let’s take another example, “echo hello” here we have “hello” as an input to the echo command:
root@vps004:~# echo hello
hello
Options
After the command name, you can specify options that modify how the command behaves (some commands support options, and some don’t). Options are powerful tools that customize commands to meet your specific needs. Let's look at some common commands with options to understand what options actually do:
Example 1: “ls”
command, This basic command lists the contents of the current directory (folder)
root@vps004:~# ls
snap test
we can see that in our current directory (folder) we have basically two other directories (folders) called snap and test.
By adding the -l option, you transform the output into a detailed long format that shows permissions, ownership, file size, and modification date. This option doesn't change what the command does (listing files & directories) but changes how it presents the information.
root@vps004:~# ls -l
total 8
drwx------ 3 root root 4096 Mar 5 17:03 snap
drwxr-xr-x 3 root root 4096 Mar 29 14:46 test
Example 2: “grep” command, The following command searches for the word "error" in file named logfile.txt (note “error” here act as an input to our grep command)
grep "error" logfile.txt
The -i
option makes grep case-insensitive, so it will find "error", "ERROR", "Error", etc. The option modifies the search behavior while keeping the core functionality.
grep -i "error" logfile.txt
Example 3: “ping”
command, The following command sends continuous ping requests to google.com until manually stopped (google.com here act as our input to the ping command)
root@vps004:~# ping google.com
PING google.com (142.250.185.142) 56(84) bytes of data.
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=1 ttl=59 time=3.42 ms
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=2 ttl=59 time=3.46 ms
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=3 ttl=59 time=3.47 ms
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=4 ttl=59 time=3.43 ms
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=5 ttl=59 time=3.41 ms
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=6 ttl=59 time=3.49 ms
The -c 2 option tells ping to stop after sending exactly 2 packets. Here, the option limits the command's execution (again google.com act as our input to the ping command while -c 2 act as our option to customize the command behavior instead of continuously sending packets, we are only sending 2 packets)
root@vps004:~# ping -c 2 google.com
PING google.com (142.250.185.142) 56(84) bytes of data.
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=1 ttl=59 time=3.44 ms
64 bytes from fra16s50-in-f14.1e100.net (142.250.185.142): icmp_seq=2 ttl=59 time=3.44 ms
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 3.442/3.443/3.444/0.001 ms
Option Formats
Options in Linux commands come in different formats, allowing you to control command behavior in flexible ways. Let's explore these formats using our previous examples.
Short Form Options: Short options consist of a single character preceded by a dash (-). They're compact and quick to type, in all of our previous examples we have used the short form options.
grep -i "error" logfile.txt
ping -c 2 google.com
Long Form Options: are words preceded by double dashes (
--
). They're more descriptive and easier to understand.
Going back to our examples above, and specifically let’s check “grep -i”:
grep -i "error" logfile.txt #Short Form
grep --ignore-case "error" logfile.txt #Long Form
these above two commands are doing the same thing, searching the word “error” in logfile.txt, but the option used in the first command is the short form option, while we used the long form option in the second command.
let’s take another example, this time with the “ping” command:
ping -c 2 google.com
ping --count=2 google.com
Again both commands doing the same thing (sending 2 ICMP echo request packets to google.com) the only difference is that we used the short form option in the first command -c 2, while used the long form option in the second command --count=2
It’s worth mentioning that not all commands have long-form options!
Options Chaining
Options can be combined in various ways to execute complex commands concisely. Let's explore options chaining for both short and long formats using our familiar examples.
Short Form Options Chaining
Short options can typically be combined by placing them after a single dash.
grep -i "error" logfile.txt
the short form option -i Searches case-insensitively for the word "error" in our logfile.txt as we already described above.
grep -n "error" logfile.txt
the short form option -n shows the line number where there’s a match for our keyword “error” while searching the file
now we will combine/chain both short form options in single command that searches case-insensitively AND shows line numbers:
grep -in "error" logfile.txt
The order of the options after the dash generally doesn't matter, so -in and -ni would perform identically, also you can give each option it’s own dash (-) and that will not be a problem, and you can chain as many options as you want as long as these options are valid for the command itself.
You can now see that all the subsequent commands are fundamentally identical and will provide the same output, with the only distinction being the options we have included in the command.
grep -ni "error" logfile.txt
grep
-in "error" logfile.txt
grep
-i -n "error" logfile.txt
grep
-n -i "error" logfile.txt
Long Form Options Chaining
Unlike short options, long options cannot be combined into a single option. Each long option must be specified separately with its own double dashes.
CommandName --LongForm1 --LongForm2 --LongForm3
Going to back to our example, the following is the short form of options chaining:
grep -in "error" logfile.txt
while the following command is the long form option chaining:
grep --ignore-case --line-number "error" logfile.txt
Again, technically both commands do the the same thing the only difference is that first command “grep -in "error"
logfile.txt” is using short form options while the second command “grep --ignore-case --line-number "error" logfile.txt”
is using long form options.
Options with Arguments
When working with command options, many require additional information to function properly. These extra pieces of information are called arguments or inputs for the options. They specify exactly how the option should modify the command's behavior.
Understanding Option Arguments
Option arguments provide necessary details that tell the option exactly what to do. Let's explore this concept which we already seen with the “ping” command:
ping -c 5 google.com
-c
is the option that limits the number of packets sent5
is the argument (or input) for the-c
option that specifies exactly how many packets to sendWithout this argument, the option would be meaningless - the command needs to know how many packets you want to send with the ping command
Now let’s explore another command which is the “cal” command and provide some options with it’s arguments:
root@vps004:~# cal -B 1 -A 1 april 2025
March 2025 April 2025 May 2025
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31
The
-B
option stands for "Before"It tells
cal
to display a specified number of months before the selected month1
is the argument for the-B
optionThis argument specifies exactly how many months before to display (in this case, just one month)
The
-A
option stands for "After"It tells
cal
to display a specified number of months after the selected month1
is the argument for the-A
optionThis argument specifies exactly how many months after to display (in this case, just one month)
Summary
Commands are broken into 3 main parts = CommandName -Options Inputs.
Commands are simply tiny computers programs that is installed in your OS.
CommandName (program) need to be on the shell’s search path
Shell Search path is just list of folders that store those programs (commands)
Commands operate on inputs (operands)
Options modify command’s behavior.
Options can be short-form or long-form options depending on each command
Both long and short form options can be chained.
Option could have their own inputs (called Arguments)