Table of contents
- Introduction π
- 1. To view what's written in a file π
- 2. To change the access permissions of files π
- 3. To check which commands you have run till now π
- 4. To remove a directory/ Folder ποΈ
- 5. To create a fruits.txt file and to view the content π
- 6. Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guavaπππππ₯ππ
- 7. To Show only top three fruits from the file π
- 8. To Show only bottom three fruits from the file π»
- 9. To create another file Colors.txt and to view the content π
- 10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey πΉπβͺβ«π΅πππ³
- 11. To find the difference between fruits.txt and Colors.txt file πππ
- Conclusion π
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.