What is Linux Operating system and Benefits of Linux? How to Run shell scripting in Linux?

Linux Introduction:

Linux is an Open Source Operating system developed by a Finnish student, Linus Torvalds, in 1991.

It is free to download and use.

Linux is compatible on many hardware like Macs, Mainframes, super computers, cell phones etc.

It is very resistant to malware such as viruses, spyware etc. For reference visit here.

What is an Operating System?

The hardware as well as the software need a software for interfacing between these two components to run on the hardware. This is what is called operating system.

Ex: Microsoft Office is the software

Microsoft Windows is the operating system

Laptop/desktop is the hardware

Unix vs Linux

Unix is called mother of OS which laid foundation to Linux

Unix is designed mainly for mainframes and is an enterprise OS

Linux is for computer users, developers, and servers

Linux is free, Unix is not

Unix runs on specific hardware only (AIX on IBM boxes). To learn the basics of Linux administration, visit here.

Amazon Web Services Linux:

Amazon Elastic Compute Cloud (Amazon EC2). Stability, security, and an environment which facilitates a high level of performance for applications running on Amazon EC2 are some of the reasons for which Amazon Linux AMI has been designed.

The latest EC2 instance type features are supported by Amazon Linux AMI. It comes with all the instance type packages that engender integration with AWS. All instances that run the Amazon Linux AMI are offer ongoing security and maintenance updates by AWS. Amazon EC2 users are not required to pay anything extra for availing these features.

Linux Architecture

Linux has Kernel Heart of OS, talks to H/w, provides low level services to upper layer components Shell interface between Kernel and users.

Applications/Utilities – provide most of functions to users.

ROOT:

  • Like Administrator for windows machine
  • Highest level of user/anything
  • As root anything can be performed
  • In Linux, users will have home folders
  • Home directory – is the highest level of any user folder
  • Root user – highest user.

Linux Boot process:

What happens when a power button is pressed on the Server?

BIOS – Basic Input Output System – does POST Power on Self-Test – checks whether all i/o devices are working fine (mouse monitor keyboard RAM HDD, etc.), searches loads and executes boot loader program.

MBR – Master Boot Record:

Located in the first sector of the bootable disk. ex: /dev/sda or /dev/hda

The first program to be executed in Linux, of 512 bytes, it has 3 components

1) Primary bootloader of 446 bytes

2) Partition table info in the next 64 bytes

3) MBR validation check in last 2 bytes

So, it loads and executes GRUB into memory.

The initial sector in any disk or diskette is the Master Boot Record (MBR). Information contained here is used to identify both where the OS is located and how, so that booting is enabled into the computer’s prime storage or random-access memory.

GRUB – Grand Unified Boot loader – responsible for selecting OS, loads kernel into memory.

If multiple OS images are present, one image can be chosen using GRUB.

What GRUB does is to display a splash screen. Following this, it waits for a while. During this time, if the user chooses nothing, GRUB goes back to loading the default kernel.  In other words, GRUB is used for loading and executing kernel.

Run levels:

Run level 0 – /etc/rc.d/rc0.d/

Run level 1 – /etc/rc.d/rc1.d/

Run level 2 – /etc/rc.d/rc2.d/

Run level 3 – /etc/rc.d/rc3.d/

Run level 4 – /etc/rc.d/rc4.d/

Run level 5 – /etc/rc.d/rc5.d/

Run level 6 – /etc/rc.d/rc6.d/

Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.

Programs starts with S are used during startup. S for startup.

Programs starts with K are used during shutdown. K for kill.

There are numbers right next to S and K in the program names. Those are the sequence numbers in which the programs should be started or killed.

Linux Installation

Linux can be installed using CD/USD/using iso image/using network installation like kickstart.

Linux can be installed using iso. For reference visit here.

Installation steps:

1. Select Language

2. If you are connected to the Internet, tick the box to install and select continue.

3. Choose installation Type.

4. If we want to create partitions, we can create them in the following manner.

5. Select Time Zone.

6. select keyboard layout as per our language.

7.Enter user credentials and Restart system.

Directory structure:

              /

            /root

            /tmp

            /dev/ /dev/sda, /dev/sdb

            /bin/

            /lib

            /usr

            /var

            /etc

            /home

            /boot

            /opt

Basic Commands of Linux:

ls; ls –lrt

ls list files in a directory

ls –lrt à lists files in long list format with time stamp

Make directory command:

mkdir à create directory

rm, rm –rf

rm à remove a directory

rm –rf  à removes directory recursively forcibly

pwd à shows present working directory

umask à decides the default permissions with which a file/directory will be created by a user.

chmod à change permissions of a user

chown à changes user

mv à move a file or a rename

cp, cp –r

cp à copies a file

cp –r à copies all files in a directory.

scp à secure copy protocol

Editors for file in Linux:

nano

control +x + enter to save file.

Editors usage:

Nano is for normal users. Emacs and Vim are for programmers

Vim/emacs – shows the loops /functions in different color forms, easy to understand syntax

Vi/nano – shows in plain text without colors.

To open file using command “nano filename”

SHELL SCRIPTING:

A series of commands are written so that the shell can execute them. This is what goes by the name, shell scripting. Shell scripting can join many sequences of commands that are long and repetitive into a unified and uncomplicated script. Further, storing and execution of this script at any time is enabled, as a result of which the end user needs to put in a lot lesser effort.

Benefits of Shell scripting:

Advantages:

  1. It automates the frequently performed operations
  2. It runs the sequence of commands as a single command
  3. it is very easy to use
  4. It is portable, it requires no modifications to execute in any Unix-like operating system)

Disadvantages:

  1. In relating for other programming languages, Shell scripting is relatively slower to execute
  2. Almost every time a shell command is executed, Shell scripting requires a new process Let’s show you an instance of Shell scripting and execution.

1.create a file with extension .sh

2. Write code in executable Shell script file. Open file using nano or vi command and close file.

3. execute shell file using bash with filename. We will get output while we execute script.

Conclusion:

This blog is all about Linux Operating System. We have discussed some key points such as installation of Linux Operation System, basic commands of Linux, directories structures and Shell scripting and many other related items.

We hope that our readers have found some valuable information about Linux through this blog. If you think some more concepts needed to be supplemented to this discussion, then please send your feedback in the comment section below.

Written by Jagadeesh

AWS & Cloud Engineer

Recommended blogs for you

Add a Comment

Please Rate This Post*

Your email address will not be published. Required fields are marked *