LINUX:
Linux is an free and Open-source operating system with high security. Linux is multi user based OS.
Operating System:
An Operating System (OS) is a software that acts as an interface between computer hardware components and the user.
Every computer system must have at least one operating system to run other programs. Applications like Browsers, MS Office, Notepad Games, etc., need some environment to run and perform its tasks.
The OS helps you to communicate with the computer without knowing how to speak the computer’s language. It is not possible
KERNEL: manages the Hardware Components. CPU, memory, and peripheral devices.The kernel is the lowest level of the OS.
DAEMONS: Manages are background services (printing, sound, scheduling, etc.) that either start up during boot or after you log into the desktop.
SHELL: is an environment in which we can run our commands, programs, and shell scripts. It gathers input from you and executes programs based on that input. When a program finish executing, it displays that program's output.
A shell is a program that serves as an interface between the user and the operating system. It provides a way for users to interact with the computer by accepting commands and then executing them.
Shells can be graphical (GUI-based), where users interact with the computer through windows, icons, and buttons, or they can be command-line-based, where users type text commands into a terminal.
COMMAND: A command is a specific instruction or request given to a computer's operating system or shell. It tells the computer to perform a particular action or task.
TERMINAL: A terminal, also known as a command-line interface (CLI), shell, or console, is a text-based interface for interacting with a computer's operating system. It provides a way for users to enter commands and receive text-based output.
Terminals are commonly used in Unix-based and Linux operating systems, but they also exist in Windows (Command Prompt or PowerShell) and macOS.
LINUX OS DISTRIBUTIONS: Many of the users taken the linux OS and modified according to their requirements and released into the market with different names called Linux distribution.
RedHat
Ubuntu
Debian
Centos
Fedora
Opensuse
Kali Linux
Amazon Linux
Rocky Linux
LINUX HISTORY:
In 1991, Linus Torvalds a student at the university of Helsinki, Finland, thought to have a freely available academic version of Unix started writing its own code.
After this project became the Linux kernel.
The Linux kernel is written in C language.
He wrote this program specially for his own PC
Firstly he wanted to name it as 'Freax' but later it became 'Linux'.
In 1992, he released the kernel under GNU General Public License.
Today, supercomputers, smart phones, desktop, web servers, tablet, laptops and home appliances like washing machines, DVD players, routers, modems, cars, refrigerators, etc use Linux OS.
OPEN SOURCE:
Linux is also distributed under an open-source license. Open source follows these key tenants:
It is made freely available to the public, allowing anyone to view, use, modify, and distribute the code as they see fit.
The freedom to run the program, for any purpose.
The freedom to study how the program works, and change it to make it do what you wish.
The freedom to redistribute copies so you can help your neighbour.
The freedom to distribute copies of your modified versions to others.
ARCHITECTURE:
KERNEL:
It is the core or the heart of the operating system. It's the central part that manages and facilitates communication between the computer's hardware and software.
SHELL:
A shell that allows users to interact with the operating system. There are two types of shells.
Command Line Interface (CLI): Executes the command provided by user given in the form command and display the output in terminal.
Executes the process provided by user in graphical way and output is displayed in the graphical window.
COMMAND:
It is an instruction/request given to the operating system by a user.
It tells computer to perform a particular task.
TERMINAL:
It is a text-based interface that allows you to interact with the operating system by typing commands.
It's a way for you to communicate with the linux machines.
LETS DIVE INTO PRACTICAL SESSION:
By default we are in ec2-user, but if we want to perform any action we should be in root user.
because, root is the ultimate king of linux, root has full permissions, so that we can run any command anywhere.
To login as root user : sudo -i
Here sudo : super user do
to logout from root user and go back to ec2-user : exit
In Linux we have different types of commands
SYSTEM COMMANDS
HARDWARE COMMANDS
FILE COMMANDS
PERMISSION COMMANDS
USER COMMANDS
SEARCH COMMANDS
NETWORKING COMMANDS
SYSTEM COMMANDS:
uname : used to get type of OS
uname -r : used to get kernel version of our OS
uname -a : used to get full info about OS
clear: this command is used to clear the clear (or) you can use ctrl + l as a short cut
uptime : used to get since how long our system is in running state
uptime -p : this will give only time
hostname: used to get private dns name of our system
hostname -i : used to get private ip of our system
hostnamectl set-hostname “swiggy” : used to change hostname
ip addr : used to get private IP
ip route : used to get private IP
ifconfig : used to get private IP
date : to get todays date
timedatectl : used to get timezones
timedatectl set-timezone Asia/Kolkata : used to change Timezone to IST
who : used to see how many users have been loggin into your system
whoami : used to see the current user.
ps : used to see the running processors in system
kill -9 PID : used to kill a processor
date : Shows system date and timestamp
date +”%d” : Prints day of the month (01-31)
date +”%m” : Prints the month of the year 01-12
date +”%y” : Prints only the last two digits of Year
date +”%H” : Prints the hour 00-23
date +”%M” : Prints the Minute of the hour 00-59
date +”%S” : Prints the current seconds count in the minute (00-60)
date +"%D" : Prints Date in MM/DD/YY
date +”%F” : Prints only the Full date as YYYY-MM-DD
date +”%A” : Prints the Day of the Week Saturday-Sunday
date +”%B” : Prints the month between January-December
HARDWARE COMMANDS:
lscpu (or) cat /proc/cpuinfo : Displays information about the CPU architecture
lsblk -a : Lists the information about all the block devices attached to the system
free (or) cat /proc/meminfo: Displays system memory(RAM) details in KB
free -m : Displays system memory(RAM) details in MB
df -h : Report file system disk space usage in human readable languages
FILE COMMANDS:
touch filename : used to create a file
touch aws azure gcp : used to create multiple files
touch linux{1..5} : this command will create 5 files (linux1,inux2, linux3 .... linux5)
rm filename : remove file with permissions (rm means remove)
rm -f filename : remove file without permissions (-f means forcefully)
rm -f aws azure gpc : remove multiple files without permissions
rm -f linux{1..5} : this command will remove linux files from 1 to 5 without permissions
rm -f * : used to delete all files
rm -f *.txt : used to delete all files with .txt extension
rm -f a* : this command will delete all files which are stared with “a” letter
FOLDER COMMANDS:
mkdir foldername : used to create a folder
mkdir git maven jenkins : used to create multiple folders
mkdir docker{1..5} : used to create 5 folders at the same time
rmdir foldername : used to remove empty folder
rmdir git maven jenkins : will remove multiple empty folders
rmdir docker{1..5} : used to remove 5 docker empty folders
rmdir * : used to remove all empty folder
rm -rf * : used to remove all files & folders and also it is used to remove non empty folders
LIST THE FILES:
ll : used to get list of files
ls : used to get list of files
ll vs ls
ll : will give the full info about files/folders
ls : it will give only file/folder names
CHANGE DIRECTORY:
cd foldername : used to change directory
cd : used to go to root directory
cd - : used to go to previous folder
cd ../ : used to go to one folder back
cd ../../ : used to go to 2 folders back
DIRECTORY COMMANDS:
mkdir folder1/folder2 : this will creates folder2 inside folder1
ll folder1 : used to get list of files & folder which are present in folder1
touch folder1/aws.txt : used to create file inside a folder
mkdir -p aws/azure/gcp/devops : used to create parenting folder (folder inside the folder) automatically
COPY COMMANDS:
SYNTAX: cp source destination
command: cp file1 file2
By the above command, the data from file1 copies into file2. But the problem is it will overwrite the data which are present in file2.
To overcome this issue we will use cat command.
cat source_file (file1)>> destination_file (file2)
MOVE COMMANDS:
SYNTAX: mv source destination
COMMAND : mv file1 file2
This is also called renaming a file
ll : used to see the list of files in order (A-Z)
ll -t : used to see the list of the files based on modification/creation time
ll -r : used to see the files in reverse order (Z to A)
ll -a : used to see all files including hidden
CAT COMMANDS:
cat command is used to read the data from a file, it is also used to append the data in a file
cat filename: used to read the data from a file
cat>filename : used to overwrite the data
cat>>filename: used to append the data
NOTE: Cat command is used to append the data, but here the problem is, it is not possible to modify the data. To avoid this issue we can use editor in linux.
There are 2 types of editors in linux
Vim editor
Nano editor
VIM EDITOR: It is used to edit the files in linux machines, It has 3 modes
Command mode
Insert mode
Save & quit mode
To open any file in vim editor : vim filename (or) vi filename
COMMAND MODE: this is the default mode in vim editor, It is used to perform some actions like used to copy the data, delete the data and we can make undo and redo the changes as well.
gg : used to go to 1st line of the file
G : used to go to last line of the file
M : used to go to middle of the file
4gg : used to go to 4th line of the file
17gg : used to go to 17th line of the file
:23 : used to go to 23rd line of the file
:set number : used to set numbers of the file
yy : used to copy the line
4yy : used to copy 4 lines from our cursor
p : paste the copied content
10p : paste the copied content 10 times
dd : used to delete the line
5dd : used to delete 5 lines from the cursor
u : used to undo the changes
crtl + r : used to redo the changes.
/word : used to search for a word in a file
?word : used to search for a word in a file
:%s/old/new/ : used to replace
2. INSERT MODE: This mode is used to insert the data or make any modifications in a file.
To go to insert mode : i
To go back to command mode : esc
To go to the ending of the line : A
To go to starting of this line : I
To create a new line above the cursor : O
To create a new line below the cursor : o
DIFFERENCE B/W COMMAND MODE KEYS & INSERT MODE.
If we perform command mode keys we will be in command mode only.
If we perform insert mode keys we will go to insert mode.
3. SAVE & QUIT MODE: This is used to save the data and quit from vim editor
To save the data - :w
To quit from vim editor - :q
To quit forcefully - :q!
To save & quit at a time - :wq
To save & quit forcefully at a time - :wq!
GREP (Global Regular Expression Print):
It is used to search for a word in a file
SYNTAX: grep “word” filename
grep “word” filename : used to search for a word in a file
grep -n “word” filename : it prints the data along with line numbers
grep -c “word” filename : it prints no of occurances of a word
grep -i “word” filename : used to search for a case-sensitive
USER COMMANDS:
cat /etc/passwd (or) getent passwd: used to get list of users
useradd username : used to add user
NOTE: whenever we added any user, then folder will gets created in /home directory
whenever we added any user, then group will also created
userdel username : used to delete user
NOTE: whenever we delete any user, then folder will not gets deleted in /home directory
whenever we delete any user, then group will gets deleted
userdel -r username : used to remove the user along with folder
useradd -M username : used to create a user without folder
su - username : used to switch to another user
passwd username : used to set a password to user
GROUP COMMANDS:
cat /etc/group : used to get list of groups
groupadd group_name : used to add a group
groupdel groupname : used to delete group
usermod -a -G group user : used to add a user in a group
PERMISSION COMMANDS:
chown username filename : used to change the owner of a file
chgrp groupname filename : used to change the group of a file
chown username:groupname filenames : used to change user & group at a time
chown username:groupname folder : used to change user & group at a time to folder
chown -R username:groupname folder : used to change user & group at a time to folder and along with files which are present in inside of a folder
chown username:groupname folder/* : used to change user & group to the files which are present in folder
chmod 777 filenames : used to change the permissions of a file
SEARCH COMMANDS:
It is used to search for a file, To search for a file we have 2 commands
find command
locate command
FIND COMMANDS:
SYNTAX: find path -name file_name
find . -name file : used to find a file in current directory
find /proc/ -name filename : used to find a file in proc directory
find . -type d -name folder : used to find a folder in current directory
find . -type f -name <file1.txt> : used to find a file in current directory
find . -type f -perm 777 : Finds all the files whose permissions are 777 in the current directory
find . -type f ! -perm 777 : Finds all the files whose permissions are NOT 777 in the current directory
find / -user <username> : Finds all the files specific user owned in / directory
find / -group groupname : Finds all the files specific group owned in / directory
LOCATE COMMANDS:
SYNTAX: locate filename
NOTE: If you are using locate command, we have to update the db of linux before performing locate command.
find vs locate : find commands will search as per the path that we mentioned in command, but locate command will search for a file on entire database.
Conclusion
Linux is the backbone of the DevOps ecosystem, offering unparalleled flexibility, scalability, and performance. Whether you're automating workflows, managing containers, or deploying applications, mastering Linux is essential for any DevOps professional. By integrating Linux into your DevOps toolkit, you not only gain access to a powerful operating system but also open doors to innovation and efficiency. Embrace Linux, and take your DevOps skills to the next level.
If you love stories that inspire learning, growth, and productivity, consider subscribing for more! If this article added value to your journey, your support would mean the world to me — only if it’s within your means. Let’s stay connected on LinkedIn too. Thank you for reading!