Unleash the Power of Linux: Commands with a Twist

  1. View File Content with Line Numbers

    • Create a file: touch file_name

    • Edit with Vim: vim file_name (Enter content, then esc :wq to save and exit)

    • Display content: cat file_name

  2. Set File Permissions for Owner Only

    • Command: chmod 700 file_name

    • Breakdown:

      • Owner: read (4) + write (2) + execute (1) = 7

      • Group/Others: no permissions (0)

  3. Review Your Last 10 Commands

    • Command: history | tail -n 10
  4. Delete a Directory and Its Contents

    • Command: rm -r directory_name
  5. Create and Display a Fruits List

    • Create file: touch fruits.txt

    • Edit file: vim fruits.txt

    • Display content: cat fruits.txt

    • Alternatively: echo -e "Apple\nBanana\nCherry\nDate\nElderberry" > fruits.txt

  6. Add and Append Content in devops.txt

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

    • Append: echo "Pineapple" >> devops.txt

  7. Reverse the First Three Fruits

    • Command: head -n 3 devops.txt | tac
  8. Sort the Last Three Fruits Alphabetically

    • Command: tail -n 3 devops.txt | sort
  9. Create and Display a Colors List

    • Command: echo -e "Red\nPink\nWhite\nBlack\nBlue" > colors.txt
  10. Prepend "Yellow" to Colors.txt

    • Command: echo "Yellow" > temp.txt | cat colors.txt >> temp.txt | mv temp.txt colors.txt
  11. Find Common Lines Between Fruits and Colors

    • Sort files: sort fruits.txt -o fruits.txt and sort colors.txt -o colors.txt

    • Find common lines: comm -12 fruits.txt colors.txt

  12. Count Lines, Words, and Characters

    • Command: wc fruits.txt colors.txt