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:
Showcase the command to view what's written in a file.
Showcase changing the access permissions of files.
Showcase checking which commands you have run till now.
Showcase removing a directory/Folder.
Showcase creating a fruits.txt file and viewing the content.
Showcase adding content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
Showcase how to show only the top three fruits from the file.
Showcase how to show only the bottom three fruits from the file.
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:
Viewing File Contents:
To view the contents of a file we use the
cat
command.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 thechmod
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.
Checking Command History:
We use the command
history
Removing a Directory/Folder:
We use the
rm -r
command.Creating and Viewing File Contents:
To create a file we use the
touch
command to view its contents refer to example one.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.Showing Top Three Fruits:
We use the
head
command with the number of lines. In our case 3.Showing Bottom Three Fruits:
We use the
tail
command with the number of lines. In our case 3.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.