Day 3 of #90daysofdevops
Hey Techies! Welcome to this blog
In this blog, we are going to discuss some more basic commands.
What is the Linux command to
To view what's written in a file.
Use the
cat
command to view the contents of a file in Linux.Example: To view the contents of a file named
my_file.txt
, typecat my_file.txt
and press Enter.
cat my_file.txt
I love Linux
To change the access permissions of files.
Use the
chmod
command to change the access permissions of files in Linux.Example: create a file named
my_file.txt
give this file readable, writable, and executable permission for the owner, and usechmod 700 my_file.txt
.Explanation -:
Read =4
Write =2
Execute =1
sudo chmod 700 my_file.txt
To check which commands you have run till now.
Use the
history
command to see a list of commands you've run in the past.Example: Type
history
to display a history of your past commands.history
To remove a directory/ Folder.
Use the
rmdir
command to remove an empty directory orrm -r
for non-empty directories.Example: To remove a directory named
my_file
, usermdir my_file
orrm -r my_file
orrm -rf my_file
rm -rf my_file
To create a fruits.txt file and to view the content.
Use the
touch
command to create an empty file, andcat
to view its content.Example: Create a file named
fruits.txt
withtouch fruits.txt
, then view it withcat fruits.txt
.touch fruits.txt
cat fruits.txt
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
Use the
vim
editor andecho
command to add content to a file.Example: To add fruits to a file named
devops.txt
, one per line, use:vim devops.txt # the file will open into the editor then write the fruits name one by one using echo echo "Apple" echo "Mango" echo "Banana" echo "Cherry" echo "Kiwi" echo "Orange" echo "Guava"
To Show only top three fruits from the file.
Utilize the
head
command to show the top three lines of a file.Example: To display the top three fruits from
devops.txt
, usehead -n 3 devops.txt
.head -n 3 devops.txt
To Show only bottom three fruits from the file.
Use the
tail
command to show the bottom three lines of a file.Example: To display the bottom three fruits from
devops.txt
, usetail -n 3 devops.txt
.tail -n 3 devops.txt
To create another file Colors.txt and to view the content.
Use the
touch
command to create a new file andcat
to view its content.Example: Create a file named
colors.txt
withtouch colors.txt
, then view it withcat colors.txt
touch colors.txt cat colors.txt
Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
Add colors to the
colors.txt
file, one per line, using theecho
command.Example: To add colors, use:
vim colors.txt # the file will open into the editor then write the fruits name one by one using echo echo "Red" echo "Pink" echo "White" echo "Black" echo "Blue" echo "Orange" echo "Purple" echo "Grey"
To find the difference between fruits.txt and colors.txt files.
Utilize the
diff
command to find differences between two files.Example: To find the difference between
fruits.txt
andcolors.txt
, usediff fruits.txt colors.txt
.diff fruits.txt colors.txt
Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.
Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.
Happy Learning!
~kritika :)