# Day 3 Task: Basic Linux Commands

Linux command

**To view what's written in a file.**

```bash
cat <filename>
```

**To change the access permissions of files.**

```bash
chmod <permissions> <file name>
```

**To check which commands you have run till now.**

```bash
history
```

**To remove a directory/ Folder.**

```bash
rm -r
```

**To create a fruits.txt file and to view the content.**

```bash
touch fruits.txt
```

and to view

```bash
cat fruits.txt
```

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

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

This will create a new file called `devops.txt` in the current directory and populate it with the list of fruits, with each fruit on a separate line.

The `-e` option stands for "enable interpretation of backslash escapes".

When used with the `echo` command, it enables the interpretation of escape characters, such as `\n` (newline), `\t` (tab), and others. This allows us to include special characters in the output.

In the example I provided, using -e enables the interpretation of `\n`, which is used to add a newline character between each color when outputting to the file.

**Show only the top three fruits from the file.**

```bash
head -n 3 devops.txt
```

This will display the first three lines of the file, which correspond to the first three names in the list.

**Show only the bottom three fruits from the file.**

```bash
tail -n 3 devops.txt
```

**To create another file Colors.txt and to view the content.**

```bash
touch colours.txt
cat colours.txt
```

**Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey.**

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

This will create a new file called `Colors.txt` in the current directory and populate it with the list of colors, with each color on a separate line.

**To find the difference between the fruits.txt and Colors.txt files.**

```bash
diff fruits.txt Colors.txt
```

This command compares the contents of the two files and shows the differences between them.

Thanks For Reading the Blog.

@[Shubham Londhe](@TrainWithShubham)

#devops

#trainwithshubham

#linux
