Day 3 of #90DaysOfDevOps: Essential Linux Commands You Must Know

Welcome back to my journey through the #90DaysOfDevOps challenge! On Day 3, we’re diving into basic Linux commands that are crucial for DevOps engineers. Whether you're a beginner or looking to sharpen your command line skills, these commands will form the foundation for managing cloud infrastructure, file systems, and automating tasks.

In today’s task, I’ll walk you through the following Linux operations, all with examples and screenshots:

  • Viewing file contents with line numbers

  • Changing file permissions

  • Displaying the last 10 commands from your history

  • Creating, editing, and manipulating files like fruits.txt and Colors.txt

Let’s get started!


👀 Task 1: Viewing File Content with Line Numbers

To view the contents of a file and show line numbers:

bashCopy codecat -n filename.txt

Example:

bashCopy codecat -n fruits.txt

This command displays the contents of fruits.txt with line numbers, which makes it easier to track file content.

SEO Tip: Linux file viewing commands like cat are essential for DevOps professionals, enabling effective file management and troubleshooting.

Screenshot:

Using cat -n to view contents of fruits.txt with line numbers


🔒 Task 2: Changing File Permissions

To modify a file’s access permissions so that the owner can read, write, and execute while restricting others:

bashCopy codechmod 700 filename.txt

Example:

bashCopy codechmod 700 devops.txt

This sets the file's permissions, making it readable, writable, and executable only by the owner.

SEO Tip: Changing file permissions using chmod is a crucial skill in securing your Linux environment.

Screenshot:

Changing file permissions using chmod 700


🧰 Task 3: Displaying the Last 10 Commands

To view the last 10 commands you've executed, use:

bashCopy codehistory | tail -n 10

This command lists the last 10 entries from your command history, helping you recall recent actions.

SEO Tip: Using the history command allows developers to track their terminal activity and save time during debugging.

Screenshot:

Showing the last 10 commands with history


🧹 Task 4: Removing a Directory and Its Contents

To delete a directory and everything inside it, use:

bashCopy coderm -r directoryName

Example:

bashCopy coderm -r old_directory

This command recursively removes all files and subdirectories under old_directory.

SEO Tip: The rm -r command is useful for DevOps engineers when managing large directories and automating clean-up tasks.

Screenshot:

Removing directories with rm -r


🍏 Task 5: Creating and Viewing fruits.txt

To create a file and add multiple lines of content at once:

bashCopy codeecho -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > fruits.txt

Then, display the file's content with:

bashCopy codecat fruits.txt

SEO Tip: The echo command in Linux is highly versatile, useful for DevOps tasks like scripting and file creation.

Screenshot:

Creating and viewing fruits.txt with echo and cat


🍍 Task 6: Appending Content to a File

To append “Pineapple” to the end of fruits.txt:

bashCopy codeecho "Pineapple" >> fruits.txt

This command appends "Pineapple" without overwriting the existing content.

SEO Tip: Appending content with echo is a fundamental skill for file management, critical for both scripting and DevOps automation.

Screenshot:

Appending content to fruits.txt with echo


🔄 Task 7: Displaying the First Three Fruits in Reverse

To display the first three fruits in reverse order:

bashCopy codehead -n 3 fruits.txt | tac
  • head -n 3: Extracts the first three lines.

  • tac: Reverses the order of the output.

SEO Tip: Commands like head and tac are useful when working with log files, filtering data efficiently.

Screenshot:

Displaying the first three fruits in reverse order


🔤 Task 8: Sorting and Displaying the Last Three Fruits

To display the last three fruits and sort them alphabetically:

bashCopy codetail -n 3 fruits.txt | sort

This shows the last three lines from fruits.txt, then sorts them.

SEO Tip: The sort command is essential in Linux for sorting data, logs, or configuration files in a predictable order.

Screenshot:

Sorting the last three fruits alphabetically


🌈 Task 9: Creating and Viewing Colors.txt

To create the Colors.txt file and add content line by line:

bashCopy codeecho -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt

Then, view the contents of the file with:

bashCopy codecat Colors.txt

SEO Tip: Using echo and cat together makes file creation and manipulation easier in Linux, especially for automation tasks.

Screenshot:

Creating and viewing Colors.txt with echo and cat


💛 Task 10: Prepending to Colors.txt

To prepend "Yellow" at the beginning of Colors.txt:

bashCopy codeecho "Yellow" | cat - Colors.txt > temp && mv temp Colors.txt

This method safely adds "Yellow" as the first line without losing existing data.

SEO Tip: Prepending content using this technique ensures the safety of file data while modifying it.

Screenshot:

Prepend "Yellow" to Colors.txt


🔍 Task 11: Finding Common Lines Between Two Files

To find the common lines between fruits.txt and Colors.txt, use:

bashCopy codecomm -12 <(sort fruits.txt) <(sort Colors.txt)

This shows any overlapping content between the two files after sorting them.

SEO Tip: Using comm is an efficient way to compare and identify common entries across files in Linux.

Screenshot:

Finding common lines between fruits.txt and Colors.txt


📊 Task 12: Counting Lines, Words, and Characters

To count the number of lines, words, and characters in both files:

bashCopy codewc fruits.txt Colors.txt

This command provides a summary of file statistics, including line, word, and character counts.

SEO Tip: wc is a highly useful Linux command for analyzing files and verifying their contents in any DevOps environment.

Screenshot:

Using wc to count lines, words, and characters


🔧 Wrapping Up Day 3

Today's task gave me a better understanding of fundamental Linux commands. These commands are at the core of everyday operations in DevOps and cloud environments. Understanding how to manipulate files, change permissions, and handle data efficiently is crucial for anyone on the DevOps path.


💬 Join the Conversation:
What commands do you use most frequently in your DevOps tasks? Comment below and let’s discuss! Don’t forget to tag me if you’re also participating in the #90DaysOfDevOps challenge and #DevopswithSingh . Let’s keep learning together! 🚀


Hashtags:

#LinuxCommands #DevOpsJourney #LearningLinux #CloudComputing #DevOpsTasks #Automation #TrainWithShubham #90DaysOfDevOps #DevopswithSingh