Day 3 & Day 4 Task: Basic Linux and Shell Scripting Commands
This is #day3 #day4 of the #90daysofdevops challenge under the guidance of Shubham Londhe Sir.
Day 03:-
Are you ready to dive into the world of Linux commands? Let’s explore some fundamental commands that every Linux user should know.
- Viewing the Contents of a File: To see what’s written in a file, you can use the
cat
command. For example:
cat filename.txt
- Changing File Access Permissions: To modify the access permissions of files, you can use the
chmod
command. For instance:
chmod filename.txt
The first digit (7) indicates that the owner of the file (dev.txt)
has full permissions, meaning they can read, write, and execute the file.
The second digit (0) indicates that the group owner of the file does not have any permissions.
The third digit (0) indicates that other users (not the owner or in the group) also do not have any permissions.
So, in simple terms, the command
chmod 700 dev.txt
grants the owner of the filedev.txt
full control over the file, while denying any access to the group owner and other users.This ensures that only the owner can read from, write to, and execute the
dev.txt
file.
Checking Command History: To review the commands you've executed previously, simply type:
history
Removing a Directory/Folder: To delete a directory, use the
rmdir
command. Be cautious, as it removes empty directories.rmdir directory_name
Creating and Viewing a File: To create a file named fruits.txt and view its content, execute:
vim filename.txt cat filename.txt
-
Adding Content to a File: To add content to the devops.txt file, one item per line, you can use a text editor like
nano
or simply append withecho
:echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
Displaying Top Three Fruits: To display only the top three fruits from the file, you can use the
head
command:head -n 3 devops.txt
Showing Bottom Three Fruits: To show only the bottom three fruits from the file, utilize the
tail
command:tail -n 3 devops.txt
Creating and Viewing Another File: Create a file named Colors.txt and view its content:
vim Colors.txt cat Colors.txt
Adding Content to Colors.txt: Add colors to the Colors.txt file, one per line:
echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt
Finding Differences Between Files: To identify the differences between fruits.txt and Colors.txt, use the diff
command:
diff fruits.txt Colors.txt
- These Linux commands form the foundation of your journey into the world of Linux.
Day 04:- Shell Scripting
Introduction:
In the world of DevOps, understanding Linux shell scripting is like having a superpower for automating tasks and managing systems. Let's explore the basics in simple terms to unlock the magic of shell scripting.
Getting to Know Kernel and Shell
The kernel is like the boss of an operating system. It controls everything, like how programs run and how they talk to the hardware.
Now, think of the shell as your friendly assistant. It's the link between you (the user) and the boss (the kernel). You tell the shell what you want to do, and it makes sure the boss understands.
What is Linux Shell Scripting?
Linux shell scripting is like writing down a set of instructions for your assistant (the shell) to follow. These instructions can do lots of things, like moving files around, running programs, and showing messages.
Let's Dive into Tasks
Shell Scripting for DevOps: Shell scripting in DevOps is about making your assistant (the shell) do things automatically. It's like giving it a list of chores to do without having to ask every time.
Understanding #!/bin/bash: When you see "#!/bin/bash" at the top of a script, it tells your assistant (the shell) which language to use to understand your instructions. It's like speaking the same language.
Shell Script for 90DaysOfDevOps Challenge:
#!/bin/bash echo "I will complete #90DaysOfDevOps challenge"
Shell Script for User Input and Arguments:
#!/bin/bash # User Input echo "Enter your name: " read name echo "Hello, $name!" # Arguments Input echo "First argument: $1" echo "Second argument: $2"
Illustrating If-Else in Shell Scripting:
#!/bin/bash # Comparing Two Numbers num1=5 num2=10 if [ $num1 -gt $num2 ]; then echo "$num1 is greater than $num2" elif [ $num1 -lt $num2 ]; then echo "$num1 is less than $num2" else echo "Both numbers are equal" fi
Conclusion:
In short, getting the hang of basic Linux shell scripting is like empowering your trusty helper (the shell) to work smarter, not harder. It's like having a reliable sidekick in your DevOps adventures, making tasks feel effortless!
I trust you found this guide on learning Shell scripting for DevOps engineers both enjoyable and valuable.
Thank you for reading! ♥
Subscribe to my newsletter
Read articles from Devbrat Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Devbrat Singh
Devbrat Singh
"Aspiring DevOps & Cloud Enthusiasts" | LINUX | Git | GITHUB | AWS | DOCKER | KUBERNETES | ANSIBLE | TERRAFORM | JENKINS | NGINX