# Linux Based Commands

1. **Summary**
    
    What is the linux command to
    
    1. To view what's written in a file.
        
    2. To change the access permissions of files.
        
    3. To check which commands you have run till now.
        
    4. To remove a directory/ Folder.
        
    5. To create a fruits.txt file and to view the content.
        
    6. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
        
    7. To Show only top three fruits from the file.
        
    8. To Show only bottom three fruits from the file.
        
    9. To create another file Colors.txt and to view the content.
        
    10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
        
    11. To find the difference between fruits.txt and Colors.txt file.
        

**Task 1 - To view what's written in a file.**

Ans: `cat filename`

**Task 2 - To change the access permissions of files:**

Ans: `chmod permissions filename`

**Task 3 - To check which commands you have run till now:**

Ans: `history`

**Task 4 - To remove a directory/folder:**

Ans: `rm -r directory_name`

Task 5 - To create a `fruits.txt` file and view its content:

Ans : `touch fruits.txt cat fruits.txt`

**Task 6 - To add content to** `devops.txt` **(one line per fruit):**

Ans: `echo "Apple" >> devops.txt`

**Task 7 - To show only the top three fruits from the file:**

Ans: `head -n 3 devops.txt`

**Task 8 - To show only the bottom three fruits from the file:**

Ans: `tail -n 3 devops.txt`

**Task 9 - To create the** `Colors.txt` **file and view its content**

Ans: `touch Colors.txt (to create the .txt file)`

`cat Colors.txt (to view the file content)`

**Task 10 - To add content to** `Colors.txt` **(one line per color)**

Ans : `echo "Red" >> Colors.txt`

`echo "Pink" >> Colors.txt`

`echo "White" >> Colors.txt`

`echo "Black" >> Colors.txt`

`echo "Blue" >> Colors.txt`

`echo "Orange" >> Colors.txt`

`echo "Purple" >> Colors.txt`

`echo "Grey" >> Colors.txt`

**Task 11 - To find the difference between** `fruits.txt` **and** `Colors.txt` **files:**

Ans: `diff fruits.txt Colors.txt`
