#90DaysOfDevOps - Day 3: Linux basic commands continued...

ยท

3 min read

Introduction

Welcome to Day 3 of #90DaysOfDevOps! Today, we continue learning the next set of Linux basic commands on various file operations like create, delete, add contents, compare between files, and change file permissions. These tasks are essential for DevOps operations.

Tasks

  1. Remove a directory/folder:

    Create and delete a directory named "temp" from your current location.

    We start by creating day3 folder using mkdir. Use mkdir to create temp directory, temp/file1.txt file, temp/subdir directory, and temp/subdir/file1.txt file. Use tree command to confirm the directory structure. Use rm with -r option to remove the entire temp directory recursively. Use tree command to confirm.

  2. Create a new file:

    Create a file named "fruits.txt".

    Use touch command to create the file fruits.txt.

  3. Add content to a file and view its content:

    Open the "fruits.txt" file (if it exists) and add the following fruits, one on each line:

    Apple

    Mango

    Banana

    Cherry

    Kiwi

    Orange

    Guava

    Use touch command to create fruits.txt file. Use echo with -e option and direct the output > to the fruits.txt file. echo is command to print on the terminal. With -e option \n is treated as newline character. This is why we see the contents being added line by line. Use cat command to display the contents of fruits.txt file.

  4. Show the top three fruits from a file:

    Display only the top three fruits from the "fruits.txt" file.

    Use head command with -n and number of lines i.e. 3 option to display the first three lines of fruits.txt file.

  5. Show the bottom three fruits from a file:

    Display only the bottom three fruits from the "fruits.txt" file.

    Use tail command with -n and number of lines i.e. 3 option to display the last three lines of fruits.txt file.

  6. Change the access permissions of a file:

    Modify the permissions of the "fruits.txt" file so that only the owner can read and write to it.

    Use ls command to check the current file permissions of fruits.txt. We see that the fruits.txt file has owner read and write access, group read and write access, others read only access (-rw-rw-r--). Use chmod with g-rw to remove group read and write access, o-r to remove others read only access. Use ls command to verify. We see that the fruits.txt file now only has owner read and write access (-rw-------)

    This same thing can be done by using chmod with 600.

  7. Create another file and view its content:

    Create a file named "colors.txt" and add the following content:

    Red

    Pink

    White

    Black

    Blue

    Orange

    Purple

    Grey

    Perform this task as explained in Task 3.

  8. Find the difference between the two files:

    Determine the differences between the "fruits.txt" and "Colors.txt" files.

    Use diff command to display the differences between fruits.txt and colors.txt files. It displays what changes needs to be done to the fruits.txt file to match the contents of colors.txt file. 1,5c1,5 denotes that lines 1 to 5 of fruits.txt file need to be changed to match lines 1 to 5 of the colors.txt file.

  9. Check command history:

    View a list of commands you have run previously in the terminal.

    Use history command to get the list of commands that were executed until now.

Conclusion

๐ŸŽ‰ Congratulations! ๐ŸŽ‰ Today, you've conquered Day 3 of #90DaysOfDevOps! ๐Ÿš€ You've mastered various essential Linux commands like:

๐Ÿ‘‰ touch (to create files)

๐Ÿ‘‰ history (to check command history)

๐Ÿ‘‰ cat (to view file contents)

๐Ÿ‘‰ head (to show the top of a file)

๐Ÿ‘‰ tail (to display the end of a file)

๐Ÿ‘‰ chmod (to change file permissions)

๐Ÿ‘‰ diff (to find differences between files)

Keep up the fantastic work! ๐Ÿ’ช Stay committed and keep on leveling up your DevOps skills! ๐ŸŒŸ

"๐ŸŒฑ Keep learning, and spread the knowledge to inspire others. ๐Ÿš€๐Ÿ’ก"

ย