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

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:

     cat filename
    

  2. To change the access permissions of files:

     chmod permissions filename
    

    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:

     history
    

  4. To remove a directory/Folder:

     rmdir directory_name
    

    or

     rm -r directory_name
    

  5. To create a fruits.txt file and view the content:

     echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > fruits.txt
     cat fruits.txt
    

    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):

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

  7. To show only the top three fruits from the file:

     head -n 3 fruits.txt
    

  8. To show only the bottom three fruits from the file:

     tail -n 3 fruits.txt
    

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

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

  10. To find the difference between fruits.txt and Colors.txt file:

diff fruits.txt Colors.txt

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