Day 3: Basic Linux Commands

Table of contents

Hey folks, back with the Basic Linux Commands that will help you to get started with Linux. So this is the Day 3 challenge of #90DaysOfDevOps.

I hope you have read all my previous blogs on DevOps and Linux. In an earlier blog, we discussed what is Linux and its structure, why to use Linux, and its Basic Commands.

Basic Commands of Linux:

I created "practice" file with the touch command.

touch practice

Now practice file has been created and I had written something in it. Example: Day3 of #90DaysOfDevops Challenge. So,

  • I want to view the content of the practice file. The command is :
cat practice
chmod a+rwx practice

In this command 'a' stands for all and 'rwx' is for read, write, execute permission which means chmod command is assigning read, write, execute permissions to all levels to the practice file.

  • To check which commands you have run till now.
history
  • To remove a directory/folder
rmdir -f directory

'rmdir' means removing the directory and 'f' means removing the directory forcefully.

  • To create a fruits.txt file and to view the content.
touch fruits.txt 
cat fruits.txt

By touch command fruits.txt files has been created and cat command to view the contents of file.

  • Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

To add the contents in file we use vi command then it will open the editor and press i to insert the contents in file.

vi fruits.txt
Apple
Mango
Banana
Cherry
Kiwi
Orange
Guava
:wq!

After writing all the contents exit out the vi editor and you successfully added the contents.

  • To Show only top three fruits from the file.
head -3 fruits.txt

head command will print the upper line contents, -3 will print the first 3 lines from the fruits.txt file.

  • To Show only the bottom three fruits from the file.
tail -3 fruits.txt

tail command will print only lower line contents and -3 will print the last 3 lines of the fruits.txt file.

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

By touch command, the Colors.txt file has been created. Now to add the contents in the Colors.txt file we use vi command, it will open the editor press (i) to insert the contents in file.

vi Colors.txt
Red
Pink
White
Balck
Blue
Orange
Purple
Grey
:wq!

Here :wq! is to save the contents in file and to exit out from the vi editor after saving it.

  • To find the difference between fruits.txt and Colors.txt file.
diff fruits.txt Colors.txt

In diff command, there are special symbols to understand:

a= add

c= change

d= delete

Here (<) less than symbol means that the contents are from fruits.txt and(>) greater than from Colors.txt. (---) these three hyphens separate the contents of line 1 and line 2.

Here you'll see 1,5c1,5 which means changing the 1st to 5th line from the first file (fruits.txt) and after that 'c' is written which means change then same again change the 1st line to the 5th line from the second file (Colors.txt) to make identical (same) both files.

7c7,8 means changing 7 line from the first file (fruits.txt) to 7th and 8th line from the second file (Colors.txt).

I hope you all learned something more about Linux and you had started with Linux.

Follow me on Twitter and Hashnode for more amazing DevOps and Linux blogs.

THANK YOU !!