Day 3 Task: Basic Linux Commands with a Twist

Task: What are the Linux commands to

  1. View the content of a file and display line numbers.

    cat -n <filename>

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

  3. Check the last 10 commands you have run.

    history | tail -10

  4. Remove a directory and all its contents.

    rm -r directoryname

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

  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.

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

  8. Show the bottom three fruits from the file, and then sort them alphabetically.

  9. Create another file Colors.txt, add content (one color per line), and display the content.

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

  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.

    echo -e "Yellow\n$(cat Colors.txt)" > Colors.txt

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

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

0
Subscribe to my newsletter

Read articles from Khushbu Koradiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Khushbu Koradiya
Khushbu Koradiya