Day 3 of 90DaysOfDevops : Basic Linux Commands with a Twist
Hey everyone, I'm continuing my journey through the #90DaysOfDevOps challenge!
Today's task focused on basic Linux commands with a twist, encouraging me to go beyond the basics and explore some extra features.
Let's dive into the functions and how I tackled them using the power of Linux commands:
Tasks: What are the Linux commands to :
Q1. View the content of a file and display line numbers.
Command:
cat -n filename.txtExplanation: The
catcommand displays the content of a file. Thenflag tellscatto number all lines as it outputs the content.
Q.2 Change the access permissions of files to make them readable, writable, and executable by the owner only.
Command:
chmod 700 filename.txtExplanation: The
chmodcommand is used to change file permissions. Here, we're setting the permissions to700, which translates to read, write, and execute access for the owner only (represented by the first digit 7), and no access for the group or others (represented by the following two zeros).
Q.3 Check the last 10 commands you have run.
Command: history | tail 10
- Explanation: The
historycommand displays a list of previously executed commands. Thetailcommand with the10argument retrieves the last 10 entries from the history list.
Q.4Remove a directory and all its contents.
Command: rm -rf directory_name
- Caution: Use this command with caution! The
rmcommand with therflag recursively deletes a directory and all its contents. Thefflag forces the deletion without prompting for confirmation.
Q.5 Create a fruits.txt file, add content (one fruit per line), and display the content.
Commands:
touch fruits.txtecho "apple" >> fruits.txtecho "mango" >> fruits.txtecho "banana" >> fruits.txtcat fruits.txt
Explanation:
We first create the
fruits.txtfile usingtouch.Then, we use the
echocommand to add content line by line, appending each fruit name to thefruits.txtfile using the>>operator.Finally, we use
catto display the contents of the file.
Q.6 Add content in devops.txt (one in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava. Then, append "Pineapple" to the end of the file.
Commands:
echo "apple" >> devops.txtecho "mango" >> devops.txtecho "banana" >> devops.txtecho "cherry" >> devops.txtecho "kiwi" >> devops.txtecho "orange" >> devops.txtecho "guava" >> devops.txtecho "pineapple" >> devops.txt
Explanation: Similar to task 5, we use the touch command to create the devops.txt file line by line.
Q.7 Show the first three fruits from the file in reverse order.
Command:
head -n 3 frutits.txt|tacExplanation:
head -n 3extracts the first three lines from the top of the file.tac reverses the order of fruits, giving us the first three fruits in reverse order.
Q.8 Show the bottom three fruits from the file and sort them alphabetically.
Command:
tail -n 3 fruits.txt | sortExplanation:
tail -n 3 fruits.txtretrieves the last three lines fromfruits.txt.sortsorts the lines alphabetically,
Q.9 Create a Colors.txt file, add content (one color per line), and display the content.
Commands:
touch Colors.txtecho "red" >> Colors.txtecho "pink" >> Colors.txtecho "white" >> Colors.txtecho "black" >> Colors.txtecho "blue" >> Colors.txtecho "orange" >> Colors.txtecho "purple" >> Colors.txtecho "grey" >> Colors.txtcat Colors.txt
Q.10 Add content in Colors.txt (one in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey. Then, prepend "Yellow" to the beginning of the file.
Commands:
echo "yellow" > temp.txtcat Colors.txt >> temp.txtmv temp.txt Colors.txt
Q.11 Find and display the lines that are common between fruits.txt and Colors.txt.
- Command:
comm -12 fruits.txt Colors.txt
Explanation: The comm command compares two files. The 12 option displays only the lines that are common to both files.
Q.12 Count the number of lines, words, and characters in both fruits.txt and Colors.txt.
Command:
wc fruits.txt Colors.txtExplanation: The
wccommand counts the number of lines, words, and characters in a file. When used with multiple files, it provides a count for each file.
Output:
fruits.txt: 7 lines, 42 words, 256 characters Colors.txt: 9 lines, 54 words, 324 characters
Comments
Join the discussionNo comments yet. Be the first to comment.
Jyoti-Ranjan-Devops
Join me on a 90-day DevOps journey as I dive deep into DevOps tools and practices, from Linux basics to advanced Docker, Kubernetes, and CI/CD. I'll share daily insights, resources, and tips to help you learn, grow, and excel in the DevOps field.

