# Day 3 Task: Basic Linux Commands

Day 3 Task: Basic Linux Commands

Task: 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. `To view what's written in a file:`
    
    **cat** - 'cat' command is used to view all the contents written in a file.  
    I have created a text file with the ***'task.txt'*** name and want to check the content inside this file and get the below output.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689688447697/0bceb65a-92de-4344-95be-1ddb9a1631c6.png?auto=compress,format&format=webp align="left")
    
    `To change the access permissions of files`  
    After creating the files and directories if you want the change the permissions then we follow the below methods.
    
    1. *Numeric Method*
        
    2. *Symbolic Method*
        
    
    In both methods, the command to modify the permissions is *'****chmod'****.*  
    Basic permissions of files and directories are ***<mark>read(r)</mark>, <mark>write(w)</mark>*** and ***<mark>execute(x)</mark>.***
    
    1. Numeric Method:
        
        *Read(r) = 4; Write(w) = 2; Execute(x) = 1*
        
        Syntax:
        
        ***'chmod 755 &lt;file-name&gt;'*** to assign 755 permissions to a file
        
        *7 (r+w+x): owner permissions.*  
        *5(r+x): group owner permissions.*
        
        *5(r+x): other users permissions.*
        
    2. Symbolic Method:  
        In the symbolic method, to represent the owner permissions we use ***‘u’;***  
        to represent group permissions we use ***'g'*** and  
        to represent other user permissions we use ***'o'.***
        
        Syntax:
        
        ***'chmod <mark>g+w&nbsp;</mark>  &lt;file-name&gt;'*** *to assign write permission to the group.*
        
        ***'chmod <mark>g-w,o+w</mark> &lt;file-name&gt;'*** *to remove write for group and to add write for other users.*
        
        ***'chmod <mark>go+w</mark> &lt;file-name&gt;'*** *to add write permission to the group and other users.*
        
        ***'chmod u-r,w-w,o-x &lt;dir-name&gt;'*** *to remove read for the owner, remove write for the group and remove execute for other users.*  
        In the below example, I am changing access permissions to the file for all (owner, group and others).
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689689710038/8aca1ff9-e44e-451b-a0fe-7c01903c5db1.png?auto=compress,format&format=webp align="left")
        
    
    `To check which commands you have run till now.`
    
    ***'history'*** is one of the important features of the bash shell which stores all previously executed commands in a file called '.bash\_history' that will be available in each user's home directory.  
    We can list out all running commands till now by using the keyword '***history*'.**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689690090556/700a394c-db1e-4264-9dce-fd11f47ecb7a.png?auto=compress,format&format=webp align="left")
    
    `To remove a directory/ Folder.`
    
    ***'rm'*** *and* ***'rm -r'*** commands are used to remove a file and directory respectively.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689690328775/aa67982e-5c57-4b88-84d2-5ef148c822d9.png?auto=compress,format&format=webp align="left")
    
    `To create a fruits.txt file and to view the content.`
    
    * **'*touch*'** command is used to create empty files.
        
    * **'*cat*'** command is used to create the files, read the content of the files and write the data to the files.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689691196016/47d317b2-025b-4f1c-8ac8-50e98df5b46f.png?auto=compress,format&format=webp align="left")
        
    
    `Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.`  
    ***'vi' or 'vim'*** is used to create the files and edit the files. It comes with three modes
    
    1. *Command mode.*
        
    2. *Insert mode.*
        
    3. *Exit or Colon mode.*
        
    
    As soon as we execute the command **'*vi &lt;file-name&gt;*'** we will be entering into ***command mode*** where we can press the button **'i'** to move the cursor position to different positions and to get into ***insert mode.***
    
    ***Exit or colon mode*** is used to save the changes or quit the file with saving changes and without saving changes.  
    ***':w'*** *to save all the changes.*  
    ***':q'*** *to quit the file without saving changes.*  
    ***':wq'*** *save and quit.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689691505707/e4682efc-5dc5-4979-8028-12e04ae8a119.png?auto=compress,format&format=webp align="left")
    
    `Show only the top three fruits from the file & only the bottom three fruits from the file.`
    
    ***'head -n filename'*** command is used to view the content from the top.  
    ***'tail -n filename'*** command is used to view the content from the bottom.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689692250135/ff3bcc22-0915-460c-98c3-b179999c2402.png?auto=compress,format&format=webp align="left")
    
    `To create another file Colors.txt and add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689692378099/d7d76890-3490-4d49-84dc-f821b44f50e4.png?auto=compress,format&format=webp align="left")
    
    `To find the difference between fruits.txt and Colors.txt files.`
    
    ***'diff'*** command is used to display the differences in the files by comparing the files line by line.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689692513510/9e06625d-2085-474e-a057-f7fa00279b8e.png?auto=compress,format&format=webp align="left")
    
    > * Thanks for reading my blog.
    >
