🚀 Day 3 of #90DaysOfDevOps Challenge: Basic Linux Commands with a Twist

Kanavsingh - Oct 9 - - Dev Community

Today’s challenge in the #90DaysOfDevOps journey was all about getting comfortable with basic Linux commands while adding some fun twists. These are foundational skills for any DevOps engineer, as most of the infrastructure you'll deal with will be Linux-based.

Let's dive into today's tasks and see how to solve them with practical Linux commands.

📜 Task 1: Viewing File Content with Line Numbers
To view the contents of a file and display line numbers, we use the cat command with the -n option.

cat -n filename.txt

Example:

Image description

cat -n Devops_File --> This will display the content of fruits.txt with line numbers next to each line. Perfect for tracking changes or debugging!

🔐 Task 2: Changing File Permissions
To make a file readable, writable, and executable by the owner only, we use the chmod command with the appropriate numeric code for permissions.

chmod 700 Devops_File

Explanation:
7 means the owner has read (r), write (w), and execute (x) permissions.
0 means no permissions for the group and others.
Example:

Image description

chmod 700 Devops_File
This will restrict access to the owner only.

🕹 Task 3: Viewing Command History
To view the last 10 commands you have run in the terminal, use:

history | tail -n 10
This will show the most recent 10 commands from your shell history.

Image description

🗑 Task 4: Removing a Directory and Its Contents
The rm command with the -r option allows you to recursively remove a directory and all its contents.

rm -r directoryName
This will delete the directory and everything inside it.

Example:

Image description

rm -r old_directory
🍏 Task 5: Creating and Viewing fruits.txt
To create a file and add one fruit per line:

echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > fruits.txt
You can now view the contents with:
cat fruits.txt

Image description

🍍 Task 6: Appending to a File
To append a new line to an existing file, use the echo command with the append (>>) operator.

echo "Pineapple" >> fruits.txt
This will add "Pineapple" as the last entry in fruits.txt.

Image description

🔄 Task 7: Displaying Fruits in Reverse Order
To show the first three fruits from the file in reverse order:

head -n 3 fruits.txt | tac
Explanation:

Image description

head -n 3: Shows the first three lines.
tac: Reverses the order of lines.
📊 Task 8: Sorting the Bottom Three Fruits
To display the bottom three fruits and sort them alphabetically:

tail -n 3 fruits.txt | sort
This will show the last three fruits in alphabetical order.

Image description

🌈 Task 9: Creating Colors.txt
To create a Colors.txt file and add colors line by line:

echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt
View the content with:

Image description

cat Colors.txt
💛 Task 10: Prepending to Colors.txt
To prepend "Yellow" at the beginning of the file:

echo "Yellow" | cat - Colors.txt > temp && mv temp Colors.txt
This command adds "Yellow" as the first line in the file.

Image description

🔍 Task 11: Finding Common Lines
To find and display lines that are common between fruits.txt and Colors.txt:

comm -12 <(sort fruits.txt) <(sort Colors.txt)
This command sorts both files and compares them to find common lines.

Image description

📝 Task 12: Counting Lines, Words, and Characters
To count the number of lines, words, and characters in both files:

wc fruits.txt Colors.txt
This command displays the line, word, and character count for each file separately.

Image description

🔧 Wrapping Up Day 3
Learning Linux commands is not just about memorizing syntax; it’s about understanding how to use them effectively in day-to-day DevOps tasks. These commands are key when working with cloud infrastructure, scripting, and automation.

If you're on the #90DaysOfDevOps journey too, feel free to connect! Let’s keep learning and growing together. 💡

DevOps #LinuxCommands #Automation #Cloud #LearningJourney #TrainWithShubham #CLI #90DaysOfDevOps

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player