# Task: Basic Linux Commands

Introduction: In this blog, we will explore some fundamental Linux commands that are essential for any aspiring Linux user or developer. We'll go through various tasks to understand how to perform file operations, manipulate permissions, view command history, create and edit files, and compare file contents. So, let's dive into the world of Linux and get started!

## Task 1: To view what's written in a file.

Command: `cat filename`

Description: The `cat` command is used to concatenate and display the content of a file on the terminal.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689894762683/9532b800-6c81-4388-8bc4-d283b4859311.png align="center")

## Task 2: To change the access permissions of files.

Command: `chmod permissions filename`

Description: The `chmod` command is used to change the access permissions (read, write, execute) of a file or directory.

**Symbolic Representation**: One of the way to set permissions using letters.

* `u`: Owner
    
* `g`: Group
    
* `o`: Other
    
* `a`: All (equivalent to `ugo`)
    

To grant read and write permissions to the owner and read-only access to the group and others, you would use `chmod u=rw,g=r,o=r filename`.

for example: before modifying permissions sample is in blue color and after giving all permissions it changes to gree color.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689895583557/ed5caa60-e8f4-46a4-ad2f-99fdf8e9114e.png align="center")

## Task 3: check which commands you have run till now.

Description: The `history` command displays the list of commands executed in the current session.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689895809799/0c1695d8-0b70-4ee0-a9f8-044e9cb67de5.png align="center")

## Task 4: Remove a directory/folder

Command: `rm -r directory_name`

Description: The `rm` command is used to remove files or directories. The `-r` option is used to recursively remove a directory.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689896003411/54e682d2-6ed2-4dbf-ab5f-8e99457ff88c.png align="center")

## Task 5: Create a fruits.txt file and view the content.

Description: We first create a file named `fruits.txt` using the `touch` command and then view content to it using the `cat` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689896263349/dfc9c7d5-460f-4db5-92c7-8195e1f61bee.png align="center")

## Task 6: Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

Command: `echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt`

Description: We use the "echo" command to add delightful fruits to the "devops.txt" file.

## Task 7: To Show only the top three fruits from the file.

Command: `head -n 3 fruits.txt`

Description: The "head" command showcases the first three lines of "fruits.txt".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689896671345/78492a3a-74c4-449a-8c21-e82d6ae0fdc2.png align="center")

## Task 8:To Show only the bottom three fruits from the file.

Command: `tail -n 3 fruits.txt`

Description: The "tail" command displays the last three lines of "fruits.txt".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689896793971/dbf5b8c3-f460-4fe8-aaa5-076334684b13.png align="center")

## Task 9: To create another file Colors.txt and view the content.

Description: We first create a file named `Colors.txt` uses the `touch` command and then view content to it using the `cat` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689897095790/52ecefa7-8a02-489b-8717-ac7a4bddca59.png align="center")

## Task 10: Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

Command: `echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt`

Description: We use the "echo" command to add Colors to the "Colors.txt" file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689897303494/944b802a-725a-47bb-8b45-3460d725d077.png align="center")

## Task 11: To find the difference between devops.txt and Colors.txt file.

Command: `diff devops.txt Colors.txt`

Description: The "diff" command helps you identify discrepancies between "fruits.txt" and "Colors.txt".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689898093016/f8f54840-679f-49eb-b0a3-5e5eba488041.png align="center")

**Conclusion**: In this blog, we've covered some basic Linux commands and demonstrated how to perform essential file operations, manipulate permissions, view command history, create and edit files, and compare file contents. These commands serve as a foundation for further exploration of the Linux operating system and can be immensely helpful in your journey as a Linux user or developer. Happy learning!
