Day 3 Task: Basic Linux Commands

Day 3 Task: Basic Linux Commands

Β·

6 min read

Introduction 🌟

Welcome back to Day 3 of the thrilling #90DaysOfDevOps challenge! Today, we'll explore the wonders of Linux commands, like magical keys unlocking every DevOps engineer's potential! With these tools, navigating your Linux system becomes as easy as exploring a map. πŸš€πŸ—ΊοΈπŸ’» Get ready for a tech-packed journey! Together, we'll unravel the mysteries of essential Linux commands, discovering hidden treasures that elevate your skills. Excitement fills the air as we dive into this epic DevOps adventure! Let's go! πŸŒŸπŸ’»

1. To view what's written in a file πŸ‘€

To view the contents of a file in Linux, you can use the "cat" command. For example, let's say you have a file named "example.txt" To view what's written in this file, open your terminal and write cat example.txt:

Also we can use "less" or "more" instead of "cat" to view files as they offer better text navigation. "Cat" shows all content at once, while "less" and "more" allow scrolling and analyzing large files more easily.

2. To change the access permissions of files πŸ”’

Changing the access permissions of files in Linux is done using the "chmod" command, which stands for "change mode." πŸšͺ

In Linux, every file has three types of permissions: read (r), write (w), and execute (x). These permissions can be set for three different categories of users: the file's owner (u), the group (g) the file belongs to, and others (o) who are not the owner or part of the group.

To change the permissions, we use a combination of letters and symbols. For example:

  • "chmod u+rwx example.txt" grants read, write, and execute permissions to the file owner.

  • "chmod go-r example.txt" revokes read permission from the group and others.

Here's an example:

Let's say we have a script file named "script.sh" that we want to make executable only for the owner and read-only for others. We would use the following command:

chmod u+x,go-w script.sh

In this command:

  • "u+x" adds execute permission to the owner.

  • "go-w" removes written permission from the group and others.

After running this command, the owner of "script.sh" will be able to execute it, while the group and others will only have read access.

3. To check which commands you have run till now πŸ“œ

To check the commands you have run in the current terminal session in Linux, you can use the "history" command. πŸ“œ

4. To remove a directory/ Folder πŸ—‘οΈ

Removing a directory or folder in Linux is done using the "rmdir" or "rm" command. πŸ—‘οΈ

The "rmdir" command is used specifically to remove empty directories. For example:

The "rmdir" removes an empty "example" directory, while "rm -r" deletes directories with content and files. For example

Be cautious with "rm -r" to delete "demo" and its contents without confirmation, leading to permanent data removal. Double-check directories to avoid accidental data loss. Use commands responsibly! πŸ›‘οΈπŸ—‘οΈπŸ”πŸ§Ή

5. To create a fruits.txt file and to view the content πŸ“„

To create a "fruits.txt" file in Linux, you can use the "touch" command. πŸ“„

For example:

This command will create an empty file named "fruits.txt" in the current directory.

Next, to view the content of the "fruits.txt" file, you can use the "cat" command. 🐱

For example:

6. Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, GuavaπŸπŸ‡πŸŒπŸ’πŸ₯πŸŠπŸˆ

To add content to the "fruits.txt" file, you can use a text editor or the "echo" command to append each fruit on a new line. Here's an example using the "echo" command:

This command adds each fruit on a separate line in the "fruits.txt" file. You can then use the "cat" command to view the contents of the file:

Now your "fruits.txt" file is filled with delicious fruits! 🍎πŸ₯­πŸŒπŸ’πŸ₯πŸŠπŸ Enjoy!

7. To Show only top three fruits from the file πŸ”

To display only the top three fruits from the "fruits.txt" file, you can use the "head" command with the "-n" option, specifying the number of lines you want to see. In this case, we want to see the first three lines, which represent the top three fruits in the file. 🍎πŸ₯­πŸŒ

8. To Show only bottom three fruits from the file πŸ”»

To display only the bottom three fruits from the "fruits.txt" file, you can use the "tail" command with the "-n" option, specifying the number of lines you want to see from the end of the file. In this case, we want to see the last three lines, which represent the bottom three fruits in the file. πŸ₯πŸŠπŸ

9. To create another file Colors.txt and to view the content 🌈

To create a new file called "Colors.txt" in Linux, you can use the "touch" command followed by the desired filename. This command will create an empty file named "Colors.txt" in the current directory. Now, to view the content of the file, you can use the "cat" command:

10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey πŸŒΉπŸ’—βšͺβš«πŸ”΅πŸŠπŸ’œπŸ”³

To add the specified content to the "Colors.txt" file with each color on a separate line, you can use the following command:

🌈🎨 This command will add the colors 🌹 Red, πŸ’— Pink, ⬜ White, ⬛ Black, πŸ”΅ Blue, 🍊 Orange, πŸ’œ Purple, and πŸ”³ Grey to the "Colors.txt" file, with each color on its line. If you view the content of the file using the cat command:

11. To find the difference between fruits.txt and Colors.txt file πŸπŸŒˆπŸ”„

To find the difference between the contents of two files, such as "fruits.txt" and "Colors.txt," you can use the "diff" command. Here's an example:

πŸ”πŸŽπŸ“„πŸŽ¨ This command will compare the contents of "fruits.txt" and "Colors.txt" files. If there are any differences between the two files, the diff command will show them in the output.

With the diff command, you can easily spot the variations between two files and manage your data more efficiently. πŸ“ŠπŸ‘€

Conclusion πŸŽ‰

πŸŽ‰πŸš€ Congratulations on mastering essential Linux commands! πŸ“œπŸ’» You've gained valuable skills in file interactions, permissions, and command analysis. From creating files to exploring their contents, you've become proficient in various Linux aspects. πŸ“„πŸ“ By using commands like "ls," "chmod," and "rm," you're now a Linux command-line pro! "Less" and "more" help you read files effortlessly. πŸ“πŸ‘“ You've even created "fruits.txt" and "Colors.txt" and learned to display top and bottom items with "head" and "tail." The "diff" command aids in identifying file differences. πŸπŸ‡πŸ’ Keep practicing and exploring as your Linux adventure thrives! πŸ’ͺπŸ’‘ Embrace the command line's power and discover new possibilities in the vast Linux world. 🌐🐧 Happy DevOps exploring! πŸŒŸπŸš€πŸ”§

Stay in the loop with my latest insights and articles on cloud ☁️ and DevOps πŸš€ by following me on Hashnode, LinkedIn (www.linkedin.com/in/nishit1907), and GitHub (https://github.com/NISHIT-RAJANI).

Thank you for reading! πŸ™ Your support means the world to me. Let's keep learning, growing, and making a positive impact in the tech world together.

Β