Day Three: More Linux Commands - The #90DaysOfDevOps Challenge

Day Three: More Linux Commands - The #90DaysOfDevOps Challenge

Welcome to Day 3 of the #90DaysOfDevOps challenge! Today, we play around with some more Linux commands.

Link to GitHub Repo for the challenge.

For Day three of the challenge, the following tasks were to be completed:

  1. Showcase the command to view what's written in a file.

  2. Showcase changing the access permissions of files.

  3. Showcase checking which commands you have run till now.

  4. Showcase removing a directory/Folder.

  5. Showcase creating a fruits.txt file and viewing the content.

  6. Showcase adding content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

  7. Showcase how to show only the top three fruits from the file.

  8. Showcase how to show only the bottom three fruits from the file.

  9. Showcase creating another file Colors.txt adding content in Colors.txt (One in each line) then finding the difference between fruits.txt and Colors.txt file.

    Let's Begin:

    1. Viewing File Contents:

      To view the contents of a file we use the cat command.

    2. Changing Access Permissions:

      Let's begin by checking the file's current permissions by listing using the long listing format. using the ls -l command.

      Each character represents a specific permission as follows:

      • r: Read permission.

      • w: Write permission.

      • x: Execute permission.

      • -: No permission.

        -rw-r--r--

        Here the owner has read and write permissions, the group associated with the file only has read permissions and others can read the file.
        To change the permissions of a file we use the chmod command.

        -rwxr-xr-x

        Now the owner can read from, write to and execute the file. The group can read from and execute the file but cannot write to it. Others can also read from and execute the file but cannot write to it.

    3. Checking Command History:

      • We use the command history

    4. Removing a Directory/Folder:

      We use the rm -r command.

    5. Creating and Viewing File Contents:

      To create a file we use the touch command to view its contents refer to example one.

    6. Adding Content to devops.txt:

      To add content to the file we use the echo command which outputs text and then we use redirection operators (> and >>) so that the output is in the file instead of the terminal. We can also chain the commands using &&

      Note: > overwrites the file if it exists, while >> appends to the file without overwriting that is why in our case the > operator is used for the first line to create a new file or overwrite existing content, while the >> operator is used for subsequent lines to append content to the existing file.

    7. Showing Top Three Fruits:

      We use the head command with the number of lines. In our case 3.

    8. Showing Bottom Three Fruits:

      We use the tail command with the number of lines. In our case 3.

    9. Finding the Difference Between Files:

      First, we will create the second file Colors.txt.

      Quick tip: If you add content to a file that does not exist it will be created.

      Then check the difference between the files using the diff command.

      Note: The diff command shows the differences between two files line by line.

That concludes our journey for Day 3 of the #90DaysOfDevOps challenge. Today we explored more Linux commands, we've covered essential commands for file manipulation, permissions, and directory management. Stay tuned for more exciting challenges and insights as we continue our DevOps journey together.