Table of contents
- Introduction
- 1. Viewing the content of a file 👀
- 2. Changing the access permissions of files🔒
- 3. Checking the command history 📜
- 4. Removing a directory/folder 🗑️
- 5. Creating and viewing the content of fruits.txt 📄
- 6. Adding content to fruits.txt (One in each line)
- 7. Showing the top 3 lines
- 8. Showing the bottom 4 lines
- 9. Creating and viewing the content of Colors.txt🌈
- 10. Add content in Colors.txt (One in each line)
- 11. Finding the difference between fruits.txt and Colors.txt
Introduction
Welcome back to Day 3 of the thrilling #90DaysOfDevOps challenge! Today, we’ll explore the wonders of Linux commands, like magical keys unlocking every DevOps engineer’s potential! With these tools, navigating your Linux system becomes as easy as exploring a map. 🚀🗺️💻 Get ready for a tech-packed journey
1. Viewing the content of a file 👀
To view the contents of a file in Linux, you can use the “cat” command. For example, let’s say you have a file named “example.txt” To view what’s written in this file, open your terminal and write cat example.txt
Also, we can use “less” or “more” instead of “cat” to view files as they offer better text navigation. cat
shows all content at once, while less
and more
allow scrolling and analyzing large files more easily.
2. Changing the access permissions of files🔒
The chmod
command enables you to change the permissions on a file. You must be a superuser or the owner of a file or directory to change its permissions.
In Linux, there are three types of owners: user, group, and others. File permissions fall into three categories: Read (4), Write(2), and Execute (1).
Below is the symbolic representation of permissions to users, groups, and others.
we can find permissions of files and folders using the long listing ls -l
on a Linux terminal.
In the output above, d represents a directory and - represents a regular file.
Permissions can be changed using two modes:
Symbolic mode
chmod u+x file.txt
Numeric Mode
chmod 764 file.txt
3. Checking the command history 📜
To check the commands you have run in the current terminal session in Linux, you can use the history
command
4. Removing a directory/folder 🗑️
The rmdir
command is used specifically to remove empty directories
The rmdir
removes an empty “example” directory, while rm -r
deletes directories with content and files.
5. Creating and viewing the content of fruits.txt 📄
The touch
command is used to create an empty file and cat
command to view the content of the file.
6. Adding content to fruits.txt (One in each line)
we are going to add content to the fruits.txt file by using Vim editor
vim fruits.txt
Press i to enable the insert mode
Apple
Mango
banana
Cherry
press Esc(escape) to exit insert mode and enable command mode
:wq
w - write the changes
q - quit vim editor
7. Showing the top 3 lines
The head
command is used to see top content with the “-n” option, specifying the number of lines you want to see.
head -n 3 fruits.txt
OR head -3 fruits.txt
8. Showing the bottom 4 lines
To show only the bottom three fruits we will use tail
command with -n option
tail -n 4 fruits.txt
OR tail -4 fruits.txt
9. Creating and viewing the content of Colors.txt🌈
We are going to use the touch command to create the file and cat command to view the content of the file
touch colors.txt
cat colors.txt
10. Add content in Colors.txt (One in each line)
vim colors.txt
Press i(insert)
Red
Pink
White
Black
Blue
Esc(escape)
:wq (write and quit that file)
11. Finding the difference between fruits.txt and Colors.txt
To find the difference between the content of the two files we can use the diff
command.
diff fruits.txt colors.txt