× back Working of Linux Why use Linux? Creation of Linux Development of Linux Linux Files Standard Unix Streams Shell and programs
← Previous Topic

Linux

How does Linux Work?

Why Use Linux?

There are several reasons why one might choose to use linux:

Events leading to the creation of Linux

The emergence of Linux, one of the world’s most widely used open-source operating systems, can be traced to several important events and the work of a few people. Below is a summary of the major events that led to the emergence of Linux.

  1. Unix development: Linux was heavily influenced by the Unix operating system developed by Bell Labs in the late 1960s and early 1970s. Unix was developed as a multi-user, multi-tasking operating system and has been widely used in science and research.
  2. Minix is born: In the early 1980s, computer science professor Andrew S. Tanenbaum created a small Unix-like operating system called Minix. Minix was developed as an educational tool and the source code was made available to students.
  3. Linux is born: In 1991, a 21-year-old student named Linus Torvalds began working on a new operating system, he named it Linux. Linus was inspired by his Minix and used its source code as a starting point for his own projects. He also drew heavily on Unix design principles.
  4. Release of Linux 0.01: In September 1991, Linus released the first version of his Linux called Linux 0.01. It was a command-line operating system and was freely distributed on the Internet.
  5. Linux community development: In the years that followed, Linux quickly gained popularity among programmers and enthusiasts. A community of developers began to form around Linux, contributing to the development of the operating system by writing code, filing bug reports, and providing feedback.
  6. Enterprise Adoption: In the late 1990s and early 2000s, the open- source nature of Linux made it more flexible, cost-effective, and more secure than proprietary operating systems such as Windows, making it a popular choice for enterprises and businesses. started being hired by companies. This increased acceptance led to the development of commercial support and services for Linux.
  7. Linux Distribution Growth: As Linux became more popular, various groups of developers began creating their own versions of the operating system, called distributions (distro). Some of the most popular distributions are Red Hat, Debian, and Ubuntu. These distros contain the Linux kernel and a number of packages of easy-to-use tools and software that make using Linux easy for both developers and end users.
  8. Linux in the Consumer Market: Linux has also entered the consumer market with the advent of Linux-based mobile devices, smart TVs, and other consumer electronics.

Development of Linux

The Linux ecosystem is a constantly evolving and expanding platform, so there is a lot of development going on. Notable recent developments include:

Linux Files

Absolute and Relative Pathnames

  • A path is a unique location of a file or a folder in a file system of an OS. A path to a file is combination of / and alpha-numeric characters.

Absolute Pathname

  • An absolute path is defined as the specifying the location of a file or directory from the root directory (/).

To write an abosulte path-name:

  • Start at the root directory (/) and work down.
  • Write a slash (/) after every directory name (last one is optional)
  • For example:
                                          
    $cat abc.sql
                                        
                                    
    Note: we don't have to write '$' its already written in terminal.
    'cat' command is used for displaying content of a file, in this case abc.sql.
    The above command only work when there is a file 'abc.sql' in the current directory.
                                          
    $cat /home/database/abc.sql
                                        
                                    
    In the above example, if the first character of a pathname is /, the file’s location must be determined with respect to root.
  • An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory.

Relative path

  • Relative path is defined as the path related to the present working directly(pwd).
  • It starts at your current directory and never starts with a /.
  • To be more specific let’s take a look on the below figure in which if we are looking for photos then absolute path for it will be provided as /home/jono/photos but assuming that we are already present in jono directory then the relative path for the same can be written as simple photos.

Using . and .. in Relative Path-names

  • Linux offers a shortcut in the relative pathname that uses either the current or parent directory as reference and specifies the path relative to it.
  • A relative path name uses one of these cryptic symbols:
    • . (a single dot) - this represents the current directory.
    • .. (two dots) - this represents the parent directory.
  • If we are currently in directory /home/kt/abc and now you use .. as an argument to cd to move to the parent directory /home/kt as :
                                    
    $pwd 
    /home/kt/abc 
    $cd ..            *** moves one level up ***
    $pwd 
    /home/kt 
                                    
                                
    Note: Now when / is used with .. has a different meaning, instead of moving down a level, it moves one level up.
                            
    $pwd 
    /home/kt/abc 
    $cd ../..          *** moves two level up ***
    $pwd 
    /home
                            
                        

Example of Absolute and Relative Path

Suppose you are currently located in home/kt and you want to change your directory to home/kt/abc. Let's see both the absolute and relative path concepts to do this:

1. Changing directory with relative path concept:

                        
$pwd 
/home/kit 
$cd abc 
$pwd 
/home/kit/abc
                        
                    

2. Changing directory with absolute path concept:

                        
$pwd 
/home/kit 
$cd /home/kt/abc 
$pwd 
/home/kit/abc
                        
                    

Commands to navigate your Linux file system

pwd

  • This command displays the present working directory, letting you know where you are now.

Example ↓

                        
$pwd
/home/database/sql/dataone/
                        
                    

tree

  • The tree command displays filesystem information in a similar manner to a graphical interface. This can be handy for new Linux users who are more used to the hierarchical filesystem display in other operating systems.

cd

  • This command moves you to the specified directory, changing your present working directory location.
  • For example, to use an absolute path to move to the /etc/ssh directory, type the following command:
                                    
    $cd /etc/ssh
                                    
                                
    By using the absolute path, it doesn't matter where in the filesystem you currently are.

. .. ~

Take a shortcut. These make navigation easier. Three of them are:

  1. Single dot, or .
  2. Double dot, or ..
  3. Tilde, or ~

  • The single dot represents the present working directory, or where you are right now. Say you're in your home directory and you want to copy the sshd_config file from /etc/ssh. You can specify it with just a dot because you're copying the file to your current directory. The command looks like this:
                                    
    $sudo cp /etc/ssh/sshd_config .
                                    
                                
  • Double dots represent the parent directory, or the directory immediately above the current one in the filesystem. If there's a subdirectory namedRockin theMusicdirectory, thenMusicis the parent directory ofRock. As another example, consider where log files are stored: /var/log. In that case, var is the parent directory of log (and the filesystem root / is the parent of var).
    So, to move from the current Rock directory to the Music directory above it, type:
                                    
    $cd ..
                                    
                                
  • Similarly, the tilde character ~ represents the current, logged-on user's home directory. To copy the sshd_config file from /etc/ssh to your home directory (no matter where in the filesystem I'm presently located), type:
                                
    $cp /etc/ssh/sshd_config ~
                                
                            

Home directory

  • The directory in which you find yourself when you first login is called your home directory.
  • You can go in your home directory anytime using the following command −
                                    
    $cd ~
                                    
                                
  • Here ~ indicates the home directory. Suppose you have to go in any other user's home directory, use the following command −
                                
    $cd ~username
                                
                            
  • To go in your last directory, you can use the following command −
                                    
    $cd -
                                    
                                

ls

  • Listing Directories: To list the files in a directory, you can use the following syntax -
                                    
    $ls dirname
                                    
                                

mkdir

  • Creating Directories, directories are created by the following command -
                                    
    $mkdir mydir
                                    
                                
    Creates the directory mydir in the currect directory.
  • Here is another example -
                                
    $mkdir /tmp/test-dir
                                
                            
    This command creates the directory test-dir in the /tmp directory. The mkdir command produces no output if it successfully creates the requested directory.
  • If you give more than one directory on the command line, mkdir creates each of the directories. For example, −
                                    
    $mkdir docs pub
                                    
                                
    Creates the directories docs and pub under the current directory.

Creating Parent Directories

  • Sometimes when you want to create a directory, its parent directory or directories might not exitst. In this case, mkdir issues an error message as follows-
                                
    $mkdir /tmp/amrood/test
    mkdir: Failed to make directory "/tmp/amrood/test";
    No such file or directory
                                
                            
  • In such cases, you can specify the -p option to the mkdir command. It creates all the necessay directories for you. For example -
                                
    $mkdir -p /tmp/amrood/test
                                
                            

rmdir

  • Removing Directories: Directories can be deleted using the rmdir command as follows -
                                
    $rmdir dirname
                                
                            
    Note − To remove a directory, make sure it is empty which means there should not be any file or sub-directory inside this directory.
  • You can remove multiple directories at a time as follows -
                                    
    $rmdir dirname1 dirname2 dirname3
                                    
                                
    The above command removes the directories dirname1, dirname2, and dirname3, if they are empty. The rmdir command produces no output if it is successful.

mv

  • Renaming Directores: The mv (move) command can also be used to rename a directory. The syntax is as follows -
                                    
    $mv olddir newdir
    $mv mydir yourdir
                                    
                                

ls -la

  • If we enter the command to show a listing of the current working directories/files and use the -a option to list all the files and the -l option to provide the long listing, we will receive the following result
                                    
    pravin@Pravins-MacBook-Air BCA % ls -la
    total 64
    drwxr-xr-x@ 10 pravin  staff   320 Apr 18 19:01 .
    drwxrwxrwx@  8 pravin  staff   256 Feb 15 09:46 ..
    -rw-r--r--@  1 pravin  staff  8196 Jun  4 10:58 .DS_Store
    drwxr-xr-x  15 pravin  staff   480 Jun  5 12:29 .git
    -rw-r--r--   1 pravin  staff     8 Feb 18 12:13 .gitignore
    drwxr-xr-x   3 pravin  staff    96 Apr 18 19:01 .vscode
    -rw-r--r--@  1 pravin  staff  8661 May 28 09:15 index.html
    drwxr-xr-x   9 pravin  staff   288 May 21 10:34 public
    -rw-r--r--   1 pravin  staff   674 Apr 17 06:09 readme.md
    drwxr-xr-x   6 pravin  staff   192 Apr 27 16:18 resources
                                    
                                

Creating files

  • You can use vi editor to create ordinary files on any Unix system. You simply need to give the following command:
                        
$vi filename
                        
                    
  • The above command will open a file with the given filename. Now, press the key i to come into the edit mode. Once you are in the edit mode, you can start writing your content in the file as in the following program :
                        
This is unix file... and we are writing on this file.
I'm going to save this content in the file.
                        
                    
  • Press esc to come out of the edit mode
  • Press two keys Shift + Z together to come out of the file completely.
  • You will now have a file with filename in the current directory.

Editing files

  • You can edit an existing file using the vi editor.
                        
$vi filename
                        
                    
  • Once the file in opened, you can come in the edit mode by pressing the key i and then you can proceed by editingg the file.

Display content of a file

  • Use cat command to see the content of a file. Following is the simple content of the above created file:
                        
$cat filename
This is unix file... and we are writing on this file.
I'm going to save this content in the file.
$
                        
                    

Copying files

  • To make a copy of a file use the cp command. The basic syntax of the command is:
                        
$cp source_file destination_file
                        
                    
  • Following is the example to create a copy of the existing file filename.
                        
$cp filename copyfile
                        
                    
  • You wil find one more file copyfile in your current directory. This file will exactly be the same as the original file filename.

Renaming files

  • We same command for files as we have used for folders.
  • To change the name of a file, use the mv command. Following is the basic syntax:
                        
$mv myold_file newfile
                        
                    

Deleting files

  • To delete an existing file, use the rm command. Following is the basic syntax:
                        
$rm filename
                        
                    
  • You can remove multiple files at a time with the command given below −
                        
$rm filename1 filename2 filename3
                        
                    

Standard Unix Streams

Under normal circumstances, every Unix program has three streams (files) opened for it when it starts up

We will discuss in detail about file permission and access modes in Unix. File ownership is an important component of Unix that provides a secure method for storing files. Every file in Unix has the following attributes −

The Permission Indicators

  • While using ls -l command, it displays various information related to file permission as follows:
                    
 $ls -l /home/amrood
-rwxr-xr-- 1 amrood users 1024 Nov 2 00:10 myfile 
drwxr-xr--- 1 amrood users 1024 Nov 2 00:10 mydir
                    
                
  • Here, the first column represents different access modes, i.e., the permission associated with a file or a directory.
  • The permissions are broken into groups of threes, and each position in the group denotes a specific permission, in this order: read (r), write (w), execute (x):
    • The first three characters (2-4) represent the permissions for the file's owner. For example, -rwxr-xr-- represents that the owner has read (r), write (w) and execute (x) permission.
    • The second group of three characters (5-7) consists of the permissions for the group to which the file belongs. For example, -rwxr-xr-- represents that the group has read (r) and execute (x) permission, but no write permission.
    • The last group of three characters (8-10) represents the permissions for everyone else. For example,-rwxr-xr--represents that there isread (r) only permission.

File Access Modes

The permissions of a file are the first line of defense in the security of a Unix system. The basic building blocks of Unix permissions are the read, write, and execute permissions, which have been described below :

  • Read: Grants the capability to read, i.e., view the contents of the file.
  • Write: Grants the capability to modify, or remove the content of the file.
  • Execute: User with execute permissions can run a file as a program.

Directory Access Modes

Directory access modes are listed and organized in the same manner as any other file. There are a few differences that need to be mentioned:

  • Read: Access to a directory means that the user can read the contents. The user can look at the filenames inside the directory.
  • Write: Access means that the user can add or delete files from the directory.
  • Execute: Executing a directory doesn't really make sense, so think of this as a traverse permission. A user must have execute access to the bin directory in order to execute the ls or the cd command.

Changing Permissions

To change the file or the directory permissions, you use the chmod (change mode) command. There are two ways to use chmod — the symbolic mode and the absolute mode.

Using chmod in Symbolic Mode

The easiest way for a beginner to modify file or directory permissions is to use the symbolic mode. With symbolic permissions you can add, delete, or specify the permission set you want by using the operators in the following table.

                    
Sr. No          Chmod operator & Description
  1             +   Adds the designated permission(s) to file or directory
  2             -   Removes the designated permission(s) to file or directory
  3             =   Sets the designated permission(s).
                    
                

Here's an example using testfile. Running ls -l on the testfile shows that the file's permissions are as follows

                        
$ls -l testfile
-rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile
                        
                    

Then each example chmod command from the preceding table is run on the testfile, followed by ls –l, so you can see the permission changes

                        
$chmod o+wx testfile
$ls -l testfile
-rwxrwxrwx 1 amrood users 1024 Nov 2 00:10 testfile 
$chmod u-x testfile
$ls -l testfile
-rw-rwxrwx 1 amrood users 1024 Nov 2 00:10 testfile 
$chmod g = rx testfile
$ls -l testfile
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile
                        
                    

Here's how you can combine these commands on a single line

                        
$chmod o+wx,u-x,g = rx testfile
$ls -l testfile
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile
                        
                    

Using chmod with Absolute Permissions

The second way to modify permissions with the chmod command is to use a number to specify each set of permissions for the file.

Each permission is assigned a value, as the following table shows, and the total of each set of permissions provides a number for that set.

                            
Number   Octal Permission Representation                                     Ref 
  0          No permission                                                   ---
  1          Execute permission                                              --x
  2          Write permission                                                -w-
  3          Execute and write permission: 1 (execute) + 2 (write) = 3       -wx
  4          Read permission                                                 r--
  5          Read and execute permission: 4 (read) + 1 (execute) = 5         r-x
  6          Read and write permission: 4 (read) + 2 (write) = 6             rw-
  7          All permissions: 4 (read) + 2 (write) + 1 (execute) = 7         rwx
                            
                        

Here's an example using the testfile. Running ls -1 on the testfile shows that the file's permissions are as follows:

                            
$ls -l testfile
-rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile
                            
                        

Then each example chmod command from the preceding table is run on the testfile, followed by ls –l, so you can see the permission changes

                                
$ chmod 755 testfile
$ls -l testfile
-rwxr-xr-x 1 amrood users 1024 Nov 2 00:10 testfile $chmod 743 testfile
$ls -l testfile
-rwxr---wx 1 amrood users 1024 Nov 2 00:10 testfile $chmod 043 testfile
$ls -l testfile
----r---wx 1 amrood users 1024 Nov 2 00:10 testfile
                                
                            

Changing Ownership

The chown command changes the ownership of a file. The basic syntax is as follows:

                    
$chown user filelist
                    
                

The value of the user can be either the name of a user on the system or the user id (uid) of a user on the system.
The following example will help you understand the concept

                    
$chown amrood testfile
$
                    
                

Changes the owner of the given file to the user amrood.
NOTE − The super user, root, has the unrestricted capability to change the ownership of any file but normal users can change the ownership of only those files that they own.

Changing Group Ownership

The chgrp command changes the group ownership of a file. The basic syntax is as follows

                    
$ chgrp group filelist
                    
                

The value of group can be the name of a group on the system or the group ID (GID) of a group on the system.
Following example helps you understand the concept:

                        
$ chgrp special testfile 
$ 
                        
                    

Changes the group of the given file to special group.

SUID and SGID File Permission

Often when a command is executed, it will have to be executed with special privileges in order to accomplish its task.

As an example, when you change your password with the passwd command, your new password is stored in the file /etc/shadow.

As a regular user, you do not have read or write access to this file for security reasons, but when you change your password, you need to have the write permission to this file. This means that the passwd program has to give you additional permissions so that you can write to the file /etc/shadow.

Additional permissions are given to programs via a mechanism known as the Set User ID (SUID) and Set Group ID (SGID) bits.

When you execute a program that has the SUID bit enabled, you inherit the permissions of that program's owner. Programs that do not have the SUID bit set are run with the permissions of the user who started the program.

This is the case with SGID as well. Normally, programs execute with your group permissions, but instead your group will be changed just for this program to the group owner of the program.

The SUID and SGID bits will appear as the letter "s" if the permission is available. The SUID "s" bit will be located in the permission bits where the owners’ execute permission normally resides.
For example, the command

    
$ ls -l /usr/bin/passwd
-r-sr-xr-x 1 root bin 19031 Feb 7 13:47 /usr/bin/passwd* $
    

Shows that the SUID bit is set and that the command is owned by the root. A capital letter S in the execute position instead of a lowercase s indicates that the execute bit is not set.
If the sticky bit is enabled on the directory, files can only be removed if you are one of the following users:

  • The owner of the sticky directory
  • The owner of the file being removed
  • The super user, root
To set the SUID and SGID bits for any directory try the following command

                    
$ chmod ug+s dirname
$ ls -l
drwsr-sr-x 2 root root 4096 Jun 19 06:45 dirname 
$
                    
                

Shell Prompt

Shell Types

Shell scripts

  • Comments are preceded by # sign.
                            
    # this is a comment
                            
                        
  • Comments provide information about the script, such as its purpose, author, and date. The comment lines are not executed by the shell and are purely for human readability.

Example scripts

  • Scripts have .sh extension.
  • Before you add anything else to your script, you need to alert the system that a shell script is being started. This is done using the shebang construct. For example:
                            
    #!/bin/sh
                            
                        
  • This tells the system that the commands that follow are to be executed by the Bourne shell. It's called a shebang because the # symbol is called a hash, and ! symbol is called a bang.
  • To create a script containing these commands, you put the shebang line first and then add the commands:
                                
    #!/bin/bash
    pwd
    ls
                                
                            

Shell comments

  • You can put your comments in your script as follows:
                    
#!/bin/bash 

# Author: Zara Ali
# Copyright(c) Tutorialspoint.com 
# Script follows here:
pwd 
ls
                    
                

Extended Shell Scripts

  • Shell scripts have several required constructs that tell the shell environment what to do and when to do it.
  • The shell is a real programming language, complete with variables, control structures, and so forth. No matter how complicated a script gets, it is still just a list of commands executed sequentially.
  • The following script uses the read command which takes the input from the keyboard and assigns it as the value of the variable PERSON and finally prints it on STDOUT.
                    
#!/bin/sh
# Author : Zara Ali
# Copyright (c) Tutorialspoint.com # Script follows here:
echo "What is your name?" 
read PERSON
echo "Hello, $PERSON"
                    
                
  • Here is a sample run of the script:
                    
$./test.sh
What is your name? Zara Ali
Hello, Zara Ali
$
                    
                

String programs in Linux

  • String concatenation is the process of appending a string to the end of another string. This can be done with shell scripting using two methods: using the += operator, or simply writing strings one after the other. The examples below show some shell scripts that can be used to concatenate strings.

Example 1:
In this example, we will concatenate two strings using += operator. The input strings will be stored in two variables, a and b.
Code ↓

                    
#Read inputs a and b and store string variables in them.

read a b 
#append b to the string a 
a+=$b

#Output the resulting string 
echo $a
                    
                

Example 2:
In this example, we have two variables a and b, and we stored a string in each variable. We want to concatenate them one after the other. The result of concatenation will be stored in the variable c.
Code ↓

                    
#Read inputs a and b and store string variables in them. 

read a b

#concatenate the strings by writing one after the other. Store the result in c

c=$a$b

#output c
echo $c
                    
                

Problem solution:
Here, we will create a shell script program to create two variables and then print values of variables on the console screen.
Program/Source code:
The source code to create a Linux shell script program to create and print the value of variables is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

                
#!/bin/bash

# Program name: "printVar.sh"

# Linux shell script program to create and print the value of variables.

country="India"
year=2021

echo "Country name: $country" 
echo "Year: $year"
                
            

Output ↓

                
$ sh printVar.sh
Country name: India
Year: 2021
                
            

Explanation:
Here, we created two variables country, year. which are initialized with "India", 2021 respectively. After that, we printed the value of variables on the console screen using echo command.

Problem solution:
Here, we will create a shell script program to add two integer numbers and then print the sum of numbers on the console screen.
Program/Source code:
The source code to create a Linux shell script program to add two numbers is given below.

            
#!/bin/bash

# Program name: "add_two_num.sh"

# Shell script program to add two numbers.

num1=10
num2=20

num3=`expr $num1 + $num2`

echo "Sum is: $num3"
            
        

Now, we will save the shell script program with "add_two_num.sh" name.

Output ↓

            
$ sh add_two_num.sh
Sum is: 30
            
        

Explanation:
In the above program, we created two variables num1, num2 that are initialized with 10 and 20 respectively. Here, we used the expr command to add two values of variables and then print the sum of two numbers on the console screen.

Problem solution:
Here, we will create a shell script program to swap to numbers and then print both variables after swapping on the console screen.
Program/Source code:
The source code to create a Linux shell script program to swap two numbers is given below.

                    
#!/bin/bash

# Program name: "swap.sh"

# shell script program to swap two numbers.

num1=10
num2=20

echo "Before Swapping" 
echo "Num1: $num1"
echo "Num2: $num2"

num3=$num1
num1=$num2
num2=$num3

echo "After Swapping" 
echo "Num1: $num1" 
echo "Num2: $num2"
                    
                

Output ↓

                    
$ sh swap.sh
Before Swapping
Num1: 10
Num2: 20
After Swapping
Num1: num2
Num2: num3
                    
                

Previous Year Question

Q- Explain various file handling commands in Linux with example.

Explain the working of logical and relational operators in Linux.

Sol:

  • Logical and relational operatos in Linux are primarily used within shell scripting and command-line operations. These operators allow you to perform logical and relational comparisons on values or expressions to determine the truth or falsehood of a condition. They are commonly used in conditional statements, loops, and decision making processes.

Logical Operators

  • AND (&&): Represents the logical AND operation. It returns true if both operands are true, otherwise, it return fale.
  • OR (||): Represents the logical OR operation. It returns true if either of the operands is true; otherwise, it returns false.
  • NOT (!): Represents the logical NOT operation. It reverses the logical state of its operand. If a condition is true, the NOT operator makes it false, and vice versa.

These operators are typically used to combine multiple conditions or expressions and evaluate the result based on their logical relationship.
Example ↓

                    
#!/bin/bash
# This is a script to compare two numbers using logical operator.

# Assign values to variables
x=5
y=10

# Check if both conditions are true using logical AND operator (&&)
if ((x > 0)) && ((y < 10)); then
    echo "Both conditions are true."
fi

# Check if either of the conditions is true using logical OR operator (||)
if ((x > 0)) || ((y < 10)); then
    echo "At least one condition is true."
fi

# Check if a condition is false using logical NOT operator (!)
if ! ((x == y)); then
    echo "The numbers are not equal."
fi
                    
                

Relational Operators

  • Equal to (==): Checks if two values or expressions are equal.
  • Not equal to (!=): Checks if two values or expressions are not equal.
  • Greater than (>): Checks if the left operand is greater than the right operand.
  • Less than (<): Checks if the left operand is less than the right operand.
  • Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right operand.
  • Less than or equal to (<=): Checks if the left operand is less than or equal to the right operand.

These operators are primarily used for comparing values or variables and returning a true or false result based on the comparison.
Example ↓

                    
#!/bin/bash
# This is a script to compare two numbers relational operator.

# Assign values to variables
x=5
y=10

# Compare the values using relational operators
if ((x == y)); then
    echo "The numbers are equal."
elif ((x > y)); then
    echo "x is greater than y."
else
    echo "x is less than y."
fi
                    
                

Q- What are the file permissions in LINUX and how you can change the permission for a particular file?

Reference ↓