# Basic Linux Commands

1. **cat &lt;file\_name&gt;**: This command is used to view what's written in a file
    
    **cat -n &lt;file\_name&gt;:** This adds line numbers to all lines
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680102403156/ea0ef6b1-6322-4862-89ae-76ee7ec51202.png align="left")
    
2. To change the access permissions of files.
    
    **chmod:** This command is used to change the permission of files
    
    Ex. **chmod 770 &lt;file\_name&gt;** , Here **chmod** is the command and **770(user+group+other)** is the permission.
    
    ![Introduction to Linux file permissions & attributes: chmod - Globo.Tech](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ8CulAI2Nqeu6-I4WFWaMRy7xrRsU8G8zIQA&usqp=CAU align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680102467270/b5bc92ed-e125-4114-a764-708ae0de14aa.png align="center")
    
3. To change the owner of the files
    
    **chown &lt;username&gt; &lt;filename&gt;**: This command is used to change the owner of files.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680102630978/054f1b25-9bf5-404b-9ed7-c53e57d9e24f.png align="center")
    
4. **sudo:** This is used to run the command with superuser privilege.
    
5. **history:** This command is used to check which commands you have run till now.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680102683970/22354885-795b-4d80-a3d4-6e30ccf19c7b.png align="left")
    
6. **rmdir &lt;directory\_name&gt;:** This command is used to remove a directory.
    
    or
    
    **rm -r** **&lt;directory\_name&gt;**: We used this command when a directory is not empty
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680102787891/89aaa9af-5e99-43f8-975c-ac0a03b8eb96.png align="left")
    
7. **vim &lt;filename&gt;** : Vim is the text editor in Linux.
    
8. Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680102949845/05db870a-a0fa-4fdb-827a-4854833342d2.png align="left")
    
9. **head -n &lt;filename&gt;**: To show only top three fruits from the file.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680103058711/ba426a9e-14a5-4712-97f8-54358d481c50.png align="left")
    
10. **tail -n &lt;filename&gt;:** To Show only bottom three fruits from the file.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680103091045/07b91f0f-f450-470d-9330-4471570447b4.png align="left")
    
11. 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.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680103438122/00b9e225-5d02-425a-9d48-fb19e39dcb67.png align="left")
    
12. To find the difference between the fruits.txt and Colors.txt files.
    
    Here we can use **diff** commands.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680103622091/dc445801-282e-4f5b-b97a-2d83bca0e943.png align="left")
    
13. **grep:** This command is used to find a particular pattern or word.
    
    Ex. grep -i pratik test.txt
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680104451741/73002347-9397-4bcc-98c0-c22a614518dd.png align="left")
    
14. **find:** This command is used to find the files and directories
    
    **find ./ -name test.txt**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680104945472/7c3a1eb6-aa0d-4dad-ace4-08798d03e2ba.png align="left")
    
15. **apt-get install &lt;package&gt;**: To install package
    
16. **ifconfig:** Is used to get IP address
    

***Suggestions are always welcome. Thank you !!***
