#90DaysOfDevOps - Day 3: Linux basic commands continued...
Table of contents
- Introduction
- Tasks
- Remove a directory/folder:
- Create a new file:
- Add content to a file and view its content:
- Show the top three fruits from a file:
- Show the bottom three fruits from a file:
- Change the access permissions of a file:
- Create another file and view its content:
- Find the difference between the two files:
- Check command history:
- Conclusion
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
Remove a directory/folder:
Create and delete a directory named "temp" from your current location.
We start by creating
day3
folder usingmkdir
. Usemkdir
to createtemp
directory,temp/file1.txt
file,temp/subdir
directory, andtemp/subdir/file1.txt
file. Usetree
command to confirm the directory structure. Userm
with-r
option to remove the entire temp directory recursively. Usetree
command to confirm.Create a new file:
Create a file named "fruits.txt".
Use
touch
command to create the filefruits.txt
.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 createfruits.txt
file. Useecho
with-e
option and direct the output>
to thefruits.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. Usecat
command to display the contents offruits.txt
file.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 offruits.txt
file.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 offruits.txt
file.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 offruits.txt
. We see that thefruits.txt
file has owner read and write access, group read and write access, others read only access (-rw-rw-r--
). Usechmod
withg-rw
to remove group read and write access,o-r
to remove others read only access. Usels
command to verify. We see that thefruits.txt
file now only has owner read and write access (-rw-------
)This same thing can be done by using chmod with 600.
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.
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 betweenfruits.txt
andcolors.txt
files. It displays what changes needs to be done to thefruits.txt
file to match the contents ofcolors.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.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. ๐๐ก"