Shell Scripting for Devops Beginners: Part 2
In this article we revisit some of the most used and most important Linux Commands for interviews, and these Linux commands are also used on a daily basis by every Devops Engineer
In the last article, we learned about some of the basic Linux commands. In this blog post, we will cover Networking Commands, Process Management commands and loops, and conditional operators in Shell scripting, along with some interview questions.
We forgot to cover a couple of basic commands in the first part, so let’s cover that here and then jump to some cool topics.
Also learning about Absolute path and relative path, and that’s your homework.
Let’s dive right in
Basic Commands
Lets look at some basic operators
> (overwrite):
'>‘sends the output of a command into a file, replacing the file’s existing contents.Example :
echo “hello” > file.txtIf
file.txtexists → it erases everything and replace with“hello”If it doesn’t exist →
file.txtis created with the content “hello”>>(append) :‘>>’sends the output of a command into a file, but adds it at the end, without deleting existing content.Example :
echo “hello” >> file.txtIf
file.txtexists →“hello”is added at the bottomIf it doesn’t exist → it is created with “hello” in it
We will read about other operators like (‘|’) pipe.
Networking Commands
lsof -i // To check open ports ping google.com // To check if a host is reachable ipconfig // to check IP addressProcess Management
The above commands are very important in day-to-day development, especially when debugging slow systems or tracking down resource with heavy usage.
What is Pipe
(|)parameter ?Pipe parameter is used to send the output of the first commands to the second commands.
if ps -ef returns all the processes then if we do | grep “google” it will give us the processes matching the given “pattern” Google.
ps -ef | grep "google" // returns all lines which matches Google.Now, say if i want to retrieve only a specific column after finding the entire matching sentences. Like if i want the pid of the “google” senence then what would you do ?
ps -ef | awk -F ‘{print $2}’. // will print every pid of all processes ps -ef | grep "google" | awk -F '{print $2}' // prints the pid of only process which have googleWhat is awk ?
awkis a command-line tool and mini programming language for working with text, especially column-based data (like output ofps,df, logs, CSV-ish stuff).awk ‘pattern { action }’ file
It reads input line by line
Splits each line into fields ($1, $2, $3, …)
If pattern matches, it runs the { action }
Say if i want to Print a specific column for example: show only the 1st column of
df -h:df -h | awk ‘{ print $1 }’$1→ first column$2→ second column, etc.$0→ whole line
Basic Conditions and Loops
To understand this, let’s see some interview questions, so that it’’be easier for us to understand hoe these conditional operators and loops work.
Print numbers from [1, 30] divisible by 3
for i in {1..30} do if [ $((i % 3)) -eq 0 ] then echo “$i is divisible by 3” fi doneWithout
$(( ))Bash will treat numbers as plain text, not math., andname=”pradyumna” echo $name // dollar $ is used for accessing vriable[ ]is used for conditional checks.x=1 while [ $x -le 10 ] do echo “Number: $x” x=$((x + 1)) done
Print the number of ‘S’ in MISSISSIPPI
echo -n ‘MISSISSIPPI’ | # print the word (no newline) grep -o ‘S’ | # extract every ‘S’ and print one per line(purpose of -o) wc -l # count how many lines = number of S’sSort a file alphabetically
sort file.txt
And that’s a wrap. That brings us to the end of the Shell Scripting for DevOps Beginners series.
These concepts are fundamental for DevOps, SRE, Cloud, and Backend roles.
If you found this article helpful, please consider leaving a like and sharing it with your friends. And if you want more such content delivered straight to your inbox, make sure to subscribe.




