# Day 3 - Mastering Essential Linux Commands: A Practical Guide for Beginners (29 Nov, 2023)

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.
    

1. **To view what's written in a file:**
    
    ```plaintext
    cat filename
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701261946124/6e22729d-2a31-402b-a042-2ec3183fea7f.png align="left")
    
2. **To change the access permissions of files:**
    
    ```plaintext
    chmod permissions filename
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701261931643/9c33e4cf-2127-4636-901f-90a287ec9fe3.png align="center")
    
    Replace `permissions` with the desired permission code (e.g., 755) and `filename` with the actual file name.
    
3. **To check which commands you have run till now:**
    
    ```plaintext
    history
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701261903849/efe085f0-8a12-4dfb-9d51-870fa77bd527.png align="left")
    
4. **To remove a directory/Folder:**
    
    ```plaintext
    rmdir directory_name
    ```
    
    or
    
    ```plaintext
    rm -r directory_name
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701261889349/5110d7f3-7400-4f06-9c49-80f76923a956.png align="left")
    
5. **To create a fruits.txt file and view the content:**
    
    ```plaintext
    echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > fruits.txt
    cat fruits.txt
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701261865113/21c3c0b2-330d-47e9-8ecb-02cbf8eb00d5.png align="center")
    
    1. `echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava"`: This part of the command uses the `echo` command to print the specified string to the terminal. The `-e` option enables the interpretation of backslash escapes in the string. In this case, `\n` represents a newline character, so each fruit name is on a new line.
        
    2. `> fruits.txt`: This part of the command uses the output redirection operator (`>`) to redirect the output of the `echo` command to a file named `fruits.txt`. If `fruits.txt` already exists, it will be overwritten with the new content. If it doesn't exist, a new file will be created.
        
6. **To add content in devops.txt (One in each line):**
    
    ```plaintext
    echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701262308431/634aacc8-073a-4e2c-a383-abd9438ca495.png align="left")
    
7. **To show only the top three fruits from the file:**
    
    ```plaintext
    head -n 3 fruits.txt
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701262277174/0dd1fbf2-05c7-4ecd-95ca-f9dd2fd41dd1.png align="left")
    
8. **To show only the bottom three fruits from the file:**
    
    ```plaintext
    tail -n 3 fruits.txt
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701262267625/ddb2cdca-6375-447c-a532-8027708db0f1.png align="left")
    
9. **To create another file Colors.txt and view the content:**
    
    ```plaintext
    echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt
    cat Colors.txt
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701262253188/ff5ec3c3-41d4-44ae-9e4b-989cec9ed7c8.png align="left")
    
10. **To find the difference between fruits.txt and Colors.txt file:**
    

```plaintext
diff fruits.txt Colors.txt
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701262239010/f18ae8ab-8f2f-4af0-b1dc-b14bd041cf10.png align="left")

This will display the lines that differ between the two files. If there's no output, the files are identical.
