Day 3 Linux Basic Commands 2

Day 3 Linux Basic Commands 2

Day 3 of #90daysofdevops

Hey Techies! Welcome to this blog

In this blog, we are going to discuss some more basic commands.

What is the Linux command to

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

    • Use the cat command to view the contents of a file in Linux.

    • Example: To view the contents of a file named my_file.txt, type cat my_file.txt and press Enter.

    cat my_file.txt
    I love Linux
  1. To change the access permissions of files.

    • Use the chmod command to change the access permissions of files in Linux.

    • Example: create a file named my_file.txt give this file readable, writable, and executable permission for the owner, and use chmod 700 my_file.txt.

    • Explanation -:

      Read =4

      Write =2

      Execute =1

        sudo chmod 700 my_file.txt
      
  2. To check which commands you have run till now.

    • Use the history command to see a list of commands you've run in the past.

    • Example: Type history to display a history of your past commands.

        history
      
  3. To remove a directory/ Folder.

    • Use the rmdir command to remove an empty directory or rm -r for non-empty directories.

    • Example: To remove a directory named my_file, use rmdir my_file or rm -r my_file or rm -rf my_file

        rm -rf my_file
      
  4. To create a fruits.txt file and to view the content.

    • Use the touch command to create an empty file, and cat to view its content.

    • Example: Create a file named fruits.txt with touch fruits.txt, then view it with cat fruits.txt.

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

    • Use the vim editor and echo command to add content to a file.

    • Example: To add fruits to a file named devops.txt, one per line, use:

        vim devops.txt
        # the file will open into the editor then write the fruits name one by one using echo
        echo "Apple"
        echo "Mango"
        echo "Banana"
        echo "Cherry"
        echo "Kiwi"
        echo "Orange"
        echo "Guava"
      
  6. To Show only top three fruits from the file.

    • Utilize the head command to show the top three lines of a file.

    • Example: To display the top three fruits from devops.txt, use head -n 3 devops.txt.

        head -n 3 devops.txt
      
  7. To Show only bottom three fruits from the file.

    • Use the tail command to show the bottom three lines of a file.

    • Example: To display the bottom three fruits from devops.txt, use tail -n 3 devops.txt.

        tail -n 3 devops.txt
      
  8. To create another file Colors.txt and to view the content.

    • Use the touch command to create a new file and cat to view its content.

    • Example: Create a file named colors.txt with touch colors.txt, then view it with cat colors.txt

        touch colors.txt
        cat colors.txt
      
  9. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

    • Add colors to the colors.txt file, one per line, using the echo command.

    • Example: To add colors, use:

        vim colors.txt
        # the file will open into the editor then write the fruits name one by one using echo
        echo "Red"
        echo "Pink"
        echo "White"
        echo "Black"
        echo "Blue"
        echo "Orange"
        echo "Purple"
        echo "Grey"
      
  10. To find the difference between fruits.txt and colors.txt files.

    • Utilize the diff command to find differences between two files.

    • Example: To find the difference between fruits.txt and colors.txt, use diff fruits.txt colors.txt.

        diff fruits.txt colors.txt
      

Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Happy Learning!

~kritika :)

Connect with me: linkedin.com/in/kritikashaw

Follow my Blog channel: hashnode.com/@kritikashaw