# Day 3 of 90DaysOfDevops : Basic Linux Commands with a Twist

Hey everyone, I'm continuing my journey through the #90DaysOfDevOps challenge!

Today's task focused on basic Linux commands with a twist, encouraging me to go beyond the basics and explore some extra features.

Let's dive into the functions and how I tackled them using the power of Linux commands:

**Tasks: What are the Linux commands to :**

### **Q1. View the content of a file and display line numbers.**

* Command: `cat -n filename.txt`
    
* Explanation: The `cat` command displays the content of a file. The `n` flag tells `cat` to number all lines as it outputs the content.
    

### **Q.2 Change the access permissions of files to make them readable, writable, and executable by the owner only.**

* Command: `chmod 700 filename.txt`
    
* Explanation: The `chmod` command is used to change file permissions. Here, we're setting the permissions to `700`, which translates to read, write, and execute access for the owner only (represented by the first digit 7), and no access for the group or others (represented by the following two zeros).
    

### **Q.3 Check the last 10 commands you have run.**

Command: `history | tail 10`

* Explanation: The `history` command displays a list of previously executed commands. The `tail` command with the `10` argument retrieves the last 10 entries from the history list.
    

### **Q.4Remove a directory and all its contents.**

Command: `rm -rf directory_name`

* Caution: Use this command with caution! The `rm` command with the `r` flag recursively deletes a directory and all its contents. The `f` flag forces the deletion without prompting for confirmation.
    

### **Q.5 Create a fruits.txt file, add content (one fruit per line), and display the content.**

Commands:

* `touch fruits.txt`
    
* `echo "apple" >> fruits.txt`
    
* `echo "mango" >> fruits.txt`
    
* `echo "banana" >> fruits.txt`
    
* `cat fruits.txt`
    

* Explanation:
    
    * We first create the `fruits.txt` file using `touch`.
        
    * Then, we use the `echo` command to add content line by line, appending each fruit name to the `fruits.txt` file using the `>>` operator.
        
    * Finally, we use `cat` to display the contents of the file.
        

### **Q.6 Add content in devops.txt (one in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava. Then, append "Pineapple" to the end of the file.**

* Commands:
    
    * `echo "apple" >> devops.txt`
        
    * `echo "mango" >> devops.txt`
        
    * `echo "banana" >> devops.txt`
        
    * `echo "cherry" >> devops.txt`
        
    * `echo "kiwi" >> devops.txt`
        
    * `echo "orange" >> devops.txt`
        
    * `echo "guava" >> devops.txt`
        
    * `echo "pineapple" >> devops.txt`
        

Explanation: Similar to task 5, we use the `touch` command to create the `devops.txt` file line by line.

### **Q.7 Show the first three fruits from the file in reverse order.**

* Command: `head -n 3 frutits.txt|` tac
    
* Explanation:
    
    * `head -n 3` extracts the first three lines from the top of the file.
        
    * tac reverses the order of fruits, giving us the first three fruits in reverse order.
        

### **Q.8 Show the bottom three fruits from the file and sort them alphabetically.**

* Command: `tail -n 3 fruits.txt | sort`
    
* Explanation:
    
    * `tail -n 3 fruits.txt` retrieves the last three lines from `fruits.txt`.
        
    * `sort` sorts the lines alphabetically,
        

### **Q.9 Create a Colors.txt file, add content (one color per line), and display the content.**

* Commands:
    
    * `touch Colors.txt`
        
    * `echo "red" >> Colors.txt`
        
    * `echo "pink" >> Colors.txt`
        
    * `echo "white" >> Colors.txt`
        
    * `echo "black" >> Colors.txt`
        
    * `echo "blue" >> Colors.txt`
        
    * `echo "orange" >> Colors.txt`
        
    * `echo "purple" >> Colors.txt`
        
    * `echo "grey" >> Colors.txt`
        
    * `cat Colors.txt`
        

### **Q.10 Add content in Colors.txt (one in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey. Then, prepend "Yellow" to the beginning of the file.**

* Commands:
    
    * `echo "yellow" > temp.txt`
        
    * `cat Colors.txt >> temp.txt`
        
    * `mv temp.txt Colors.txt`
        

### **Q.11 Find and display the lines that are common between fruits.txt and Colors.txt.**

* Command: `comm -12 fruits.txt Colors.txt`
    

Explanation: The `comm` command compares two files. The `12` option displays only the lines that are common to both files.

### **Q.12 Count the number of lines, words, and characters in both fruits.txt and Colors.txt.**

* Command: `wc fruits.txt Colors.txt`
    
* Explanation: The `wc` command counts the number of lines, words, and characters in a file. When used with multiple files, it provides a count for each file.
    

**Output:**

`fruits.txt: 7 lines, 42 words, 256 characters Colors.txt: 9 lines, 54 words, 324 characters`

---
