Day 3 of 90days of DevOps
Here is day 3 of #90days of DevOps.
In today’s blog, we will handle files using Linux commands.
Tasks: What is the Linux command to…
To view what's written in a file.
To view the content of the file run the command
cat <filename>
To change the access permissions of files.
Run
chmod 777 <foldername>
To check which commands you have run till now.
history
as the name suggests is used to view all the commands which we have run.
To remove a directory/ Folder.
We can remove a directory by using
rm -r <directory name>
orrm -rf <directory name>
, where -r flag is used for recurring since the directory won’t be empty. It is not advised to use “-rf” since it is done when we forcefully need to delete the repository.
To create a fruits.txt file and to view the content.
We can create files using various methods such as echo, touch, vim, nano etc. Let’s see example using each method.
echo “Hello there” >> fruits.txt
touch fruits.txt
- touch is used to create a blank file.
nano fruits.txt
vim fruits.txt
cat fruits.txt
Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
Add content in fruits.txt
To Show only top three fruits from the file.
run
head -3 fruits.txt
To Show only bottom three fruits from the file.
run tail -3 fruits.txt
To create another file colors.txt and to view the content.
- vim color.txt
Add content in colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
Add the content in colors.txt file
To find the difference between fruits.txt and Colors.txt file.
Conclusion:
We have learnt various file actions using Linux commands. In the next blog, we will see more about shell scripting.