# Basic Linux Commands

**Table of Contents:**

1. View the contents of a file
    
2. Change file permissions
    
3. Check command history
    
4. Remove a directory/folder
    
5. Create and view the content of a file
    
6. Add content to fruits.txt
    
7. Show the top three fruits
    
8. Show the bottom three fruits
    
9. Create and view the content of another file
    
10. Add content to Colors.txt
    
11. Find the difference between fruits.txt and Colors.txt
    

**1\. View the contents of a file** 📄 To see what's written in a file, we use the `cat` command. For example:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690263647955/9eea9359-9a76-4dbd-844c-5b652bcd45b8.png align="center")

**2\. Change file permissions** 🔒 To modify the access permissions of files, we use the `chmod` command. It allows us to add or remove read, write, and execute permissions. For example:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690263720157/93c6837e-e3e5-40f4-8f1c-2192e76201fa.png align="center")

**3\. Check command history** ⏳ To view the list of commands you have run in the current session, simply use the `history` command:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690263758893/ac01f3ef-fee2-4c85-9cf4-307a75c9567a.png align="center")

**4\. Remove a directory/folder** 🗑️ To delete a directory and all its contents, we use the `rm` command with the `-r` (recursive) option. For example:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690263813889/cb845560-978f-443a-b431-82b5d5e10b1e.png align="center")

**5\. Create and view the content of a file** 📝 To create a new file, we use the `touch` command. For instance, to create a file named `fruits.txt`, we write:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690263872284/e46625d6-cb70-4b88-a2fe-40569f0dbcf2.png align="center")

To view the contents of `fruits.txt`, we can use the `cat` command as mentioned earlier.

**7\. Show the top three fruits** 🥇🥈🥉 To display only the top three fruits from `fruits.txt`, we use the `head` command with the `-n` option:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690263956408/8aca76bf-5ed8-4f1f-9650-a80831856406.png align="center")

**8\. Show the bottom three fruits** 🥉🥈🥇 On the other hand, to view only the bottom three fruits from `fruits.txt`, we use the `tail` command with the `-n` option:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690263993512/77a3b84f-604d-4106-a208-cf4cc05433f6.png align="center")

**10\. Create file Colors.txt and add content** 🟥🟩⬜⬛🔵🟠💜🔳

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690264157990/6906ff01-32fa-452c-9bb1-b3eb70a61201.png align="center")

**11\. Find the difference between fruits.txt and Colors.txt** ➖🔄➕ To discover the differences between these two files, we use the `diff` command:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690264198465/2feed9ea-4dcd-4fa6-bb20-903094ab2569.png align="center")

### Happy Learning !!
