Day 3 Task: Basic Linux Commands with a Twist

Day 3 Task: Basic Linux Commands with a Twist

Β·

3 min read

Mastering Basic Linux Commands: A Beginner's Guide πŸš€

Welcome to another exciting day of our DevOps journey! Today, we're diving into the essentials of Linux commands. Whether you're new to Linux or need a refresher, these commands will help you navigate and manipulate files like a pro. Let's get started! πŸ’»

Viewing the Content of a File with Line Numbers πŸ“„

To view the content of a file and display line numbers, use the cat command with the -n option. This is handy for debugging or just keeping track of long files.

With -n you can view line number as well

Changing File Access Permissions πŸ”’

To change file permissions so that only the owner can read, write, and execute, use the chmod command with 700:

Permissions are listed below:

permissionon a fileon a directory
r (read)read file content (cat)read directory content (ls)
w (write)change file content (vi)create file in directory (touch)
x (execute)execute the fileFile permissions for (-rw-rw-r--)

File permissions for (-rw-rw-r--)

positioncharactersownership
1-denotes file type
2-4rw-permission for user
5-7rw-permission for group
8-10r--permission for other

Checking the Last 10 Commands πŸ“œ

To check the commands you have run, use the history command:

To check last 10 commands use tail -10

Removing a Directory and All Its Contents πŸ—‘οΈ

To remove a directory and all its contents, use the rm command with the -r (recursive) option:

Creating and Displaying a File with Fruits πŸŽπŸŒπŸ’

First, create a fruits.txt file and add content:

One way is to add each line manually as shown below :

Or else the best way to do it is using echo -e

Add content in devops.txt (one in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava. Then, append "Pineapple" to the end of the file.🍎

To append "Pineapple" to the end of the file:

Showing the First Three Fruits in Reverse Order πŸ”„

To display the first three fruits in reverse order:

Displaying and Sorting the Bottom Three Fruits πŸ”

To display bottom 3 fruits you can use tail -3 fruits.txt

To show the bottom three fruits, then sort them alphabetically:

Creating and Displaying a Colors File 🌈

First, create a Colors.txt file and add content:

To prepend "Yellow" to the beginning of the file:

Finding Common Lines Between Two Files πŸ”—

To find and display lines that are common between fruits.txt and Colors.txt:

Counting Lines, Words, and Characters πŸ“Š

To count the number of lines, words, and characters in both fruits.txt and Colors.txt, use the wc command:

Conclusion

Linux commands are powerful tools that can significantly enhance your productivity. By mastering these basics, you're well on your way to becoming proficient in Linux, which is a crucial skill for any DevOps professional. Stay tuned as we continue our 90-day DevOps journey. There’s much more to learn and explore! 🌟

Happy learning! πŸ“šβœ¨


Feel free to reach out with any questions or thoughts in the comments below. Happy DevOps-ing! πŸš€

Β