Table of contents
- To view what's written in a file.
- To change the access permissions of files.
- To check which commands you have run till now
- To remove a directory/ Folder.
- To create a fruits.txt file and to view the content.
- Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava๐๐๐๐๐ฅ๐๐
- To Show only top three fruits from the file.
- To Show only bottom three fruits from the file.
- To create another file Colors.txt and to view the content.
- Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
- To find the difference between fruits.txt and Colors.txt file.
Welcome to Day 3 of the #90DaysOfDevOps challenge! Today, we'll explore more Linux commands, Mastering Linux commands is a skill that opens up a world of possibilities.๐๐ป Whether you're a developer, system administrator, or simply someone who wants to harness the power of the terminal, understanding these commands will empower you to work efficiently, automate tasks, and take control of your Linux experience.
To view what's written in 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 "f1.txt" To view what's written in this file, open your terminal and write cat f1.txt
cat f1.txt
To change the access permissions of files.
To change the access permissions of files interactively, you can use the
chmod
command in Linux. ๐๐The
chmod
command allows you to modify the read, write, and execute permissions of files and directories. To use it interactively, follow these steps:Open the terminal and navigate to the directory where the file is located. ๐๐ป
Type the following command, replacing
filename
with the actual name of the file you want to modify:chmod +rwx filename
This command gives the file read, write, and execute permissions to the owner, group, and others.
Now, the file's permission has changed, and you can customize it further based on your needs. Let's break down the command:
+rwx
: Adds read, write, and execute permissions.-rwx
: Removes read, write, and execute permissions.r
: Represents read permission.w
: Represents write permission.x
: Represents execute permission.To check which commands you have run till now
To check the commands you have run in the current terminal session in Linux, you can use the "history" command. ๐
history
To remove a directory/ Folder.
Removing a directory or folder in Linux is done using the "rmdir" or "rm" command. ๐๏ธ
The "rm " command is used specifically to remove file
The "rmdir" command is used specifically to remove empty directories.
For example:
rm filename
Remove an empty directory using rmdir
:
rmdir directoryname
To create a fruits.txt file and to view the content.
To create a file in Linux, you can use the "touch" command.
For example:
touch command will create a empty file.
touch filename
To view the content of file you can use cat command.
Nothing will be shown as it is empty file.
cat filename
Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava๐๐๐๐๐ฅ๐๐
To add content to the "fruits.txt" file, you can use a text editor or the "echo" command to append each fruit on a new line. Here's an example using the text editor "vim":
vim fruits.txt
When you type command vim editor will open. Enter all the fruits name and then save. To save and exit esc+ !wq.
Apple
Mango
Banana
cherry
Kiwi
Orange
Guava
To Show only top three fruits from the file.
To display only the top three fruits from the "fruits.txt" file, you can use the "head" command with the "-n" option, specifying the number of lines you want to see. In this case, we want to see the first three lines, which represent the top three fruits in the file. ๐๐ฅญ๐
cat -n fruits.txt |head -3
To Show only bottom three fruits from the file.
To display only the bottom three fruits from the "fruits.txt" file, you can use the "tail" command with the "-n" option, specifying the number of lines you want to see from the end of the file. In this case, we want to see the last three lines, which represent the bottom three fruits in the file. ๐ฅ๐๐
cat -n fruits.txt| tail -3
To create another file Colors.txt and to view the content.
To create a new file called "Colors.txt" in Linux, you can use the "touch" command followed by the desired filename. This command will create an empty file named "Colors.txt" in the current directory. Now, to view the content of the file, you can use the "cat" command:
touch colors.txt cat colors.txt
Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
We can use vim editor or echo command.
This time we'll use echo command.To add the specified content to the "Colors.txt" file with each color on a separate line, you can use the following command.
echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > colors.txt
If you view the content of the file using the cat
command:
Red
pink
white
Black
Blue
Orange
Purple
Grey
To find the difference between fruits.txt and Colors.txt file.
To find the difference between the contents of two files, such as "fruits.txt" and "Colors.txt," you can use the "diff" command. Here's an example:
diff fruits.txt colors.txt
This command will compare the contents of "fruits.txt" and "Colors.txt" files. If there are any differences between the two files, the
diff
command will show them in the output.With the
diff
command, you can easily spot the variations between two files and manage your data more efficiently
If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐ #devops #90daysofdevops #trainwithshubham #tws #LearningTogether #connections #community #Linux #LinuxCommands.