DAY 03:Basic linux commands

RishabhRishabh
3 min read

Table of contents

  1. To view what's written in a file.

To view what's written in a file we use the "cat" command. It will display all the content of a file whether it's one page or two.

We can also use different commands based on the requirements

more -It views the content of our file one page at a time

less - It views the content of our file in reverse order, but also allows us to view one line at a time

\>>To change the access permissions of files.

To change the permission of a file we use the "chmod" command.

Syntax: chmod [permission][filename]

e.g : chmod 766 filename

In this 766 represents access permission.'7' represent that the owner of the file has read , write and execute permission.'6' represent that the group has read and write permission.'6' represent all other users who have read and write permission.

\>>To check which commands you have run till now.

We use the "history" command to check which commands we have run till now.

\>>To remove a directory/ Folder.

To remove a directory/ Folder we use "rm -r"command to remove a directory /Folder

Syntax: rm -r filename.txt

  1. To create a fruits.txt file and to view the content.

To create a fruits.txt we use "touch" command and to view the content of the file we use "cat" command

e.g touch fruits.txt

cat fruits.txt

\>>Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

To add content in the devops.txt file we use the "vim" or "nano" command

e.g vim devops.txt

To insert anything in vim editor we use the 'I' button.It will let you insert values in vim editor

\>>To Show only top three fruits from the file.

The sort command can be used to sort the contents of the file in alphabetical order. You can then use the head command to display only the first three lines of the sorted file, which will be the top three fruits.

eg: sort fruits.txt |head -n 3

\>>To Show only bottom three fruits from the file.

The sort command can be used to sort the contents of the file in alphabetical order. You can then use the tailcommand to display only the last three lines of the sorted file, which will be the last three fruits.

\>>To create another file Colors.txt and to view the content and Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

To create another file Colors.txt we used vim command and to insert in that particular file Colours.txt we press I in vim editor to insert values (Red, Pink, White, Black, Blue, Orange, Purple, Grey) and enter the values and come out of vim editor we use "Esc+:wq!" to save the content of a file

\>>To find the difference between devops.txt and Colors.txt file.

We use diff command to find the difference between two files

This will compare the contents of devops.txt and Colors.txt and display the differences between the two files. The output will show which lines are unique to each file and which lines are different between the two files.

0
Subscribe to my newsletter

Read articles from Rishabh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rishabh
Rishabh