Mastering Basic Linux Commands: Your Path to DevOps Proficiency

Welcome back to our DevOps journey! Today, we'll delve into basic Linux commands that are fundamental for any DevOps practitioner. In this post, we'll explore commands related to viewing file contents, changing file permissions, managing directories, and working with files. Let's get started with Day 3's tasks!

  1. Viewing File Contents: To view the contents of a file, the cat command comes to the rescue. Simply use the following command:
bashCopy codecat <file_name>

Executing this command will display the entire content of the specified file on your terminal. You can easily examine and analyze the contents without opening the file in an editor.

  1. Changing File Permissions: The chmod command allows you to change file permissions in Linux. Here's the syntax:
phpCopy codechmod <permissions> <file_name>

Replace <permissions> with the desired permission settings, such as u+rwx (user has read, write, and execute permissions). <file_name> should be the name of the file you want to modify. This command empowers you to manage access controls and security for files in your system.

  1. Checking Command History: To view the list of commands you've executed so far in your terminal session, use the history command. Simply type:
bashCopy codehistory

This will display a numbered list of previously executed commands. It's a handy way to recall and reuse commands without retyping them.

  1. Removing a Directory/Folder: To remove a directory, you can use the rmdir command. Be cautious, as it will only work if the directory is empty. Use the following command:
arduinoCopy codermdir <directory_name>

Replace <directory_name> with the name of the directory you want to remove. If the directory contains files or subdirectories, you can use the rm command with the -r flag to remove it recursively.

  1. Creating and Viewing File Content: To create a file, such as fruits.txt, you can use the touch command:
bashCopy codetouch fruits.txt

To view the content of a file, you can utilize the cat command we discussed earlier:

bashCopy codecat fruits.txt

This will display the contents of the fruits.txt file on your terminal.

  1. Adding Content to a File: To add content to a file, such as devops.txt, with each fruit on a separate line, you can use the echo command along with the >> redirection operator:
bashCopy codeecho "Apple" >> devops.txt
echo "Mango" >> devops.txt
echo "Banana" >> devops.txt
echo "Cherry" >> devops.txt
echo "Kiwi" >> devops.txt
echo "Orange" >> devops.txt
echo "Guava" >> devops.txt

Each echo command adds a fruit to the file. The >> operator appends the output to the file.

  1. Showing Top Three Fruits from a File: To display only the top three fruits from the devops.txt file, you can use the head command with the -n option:
bashCopy codehead -n 3 devops.txt

This will show the first three fruits from the file.

  1. Showing Bottom Three Fruits from a File: To display only the bottom three fruits from the devops.txt file, you can use the tail command with the -n option:
bashCopy codetail -n 3 devops.txt

This will show the last three fruits from the file.

  1. Creating and Viewing Content of Another File: To create the Colors.txt file and view its content, you can use the following commands:
bashCopy codetouch Colors.txt
cat Colors.txt

The touch command creates the file, and the cat command displays its contents (which will be empty initially).

  1. Finding the Difference Between Two Files: To find the differences between the fruits.txt and Colors.txt files, you can use the diff command:
Copy codediff fruits.txt Colors.txt

This command will highlight the differences between the two files, if any.

Conclusion: Congratulations on mastering these essential Linux commands! By familiarizing yourself with file operations, permissions, and directory management, you are well on your way to becoming a proficient DevOps practitioner. Keep practicing and stay tuned for more exciting DevOps content on our journey!

#DevOps #LinuxCommands #FileManagement #Permissions #DirectoryOperations #CommandLine #DevOpsJourney