Day -> 3 of 90DaysOfDevOps

Linux basic commands with twist(part two)

  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.

    chmod 700 filename

    chmod 700 file1 file2 file3 - for multiple files

  3. Check the last 10 commands you have run.

    history | tail -10

  4. Remove a directory and all its contents.

    rm -r /path/to/directory

    rm used to remove and -r is used to do recursive

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

    create file and add fruits in ->

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

    display the content ->

    cat fruits.txt

  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.

    creating file and adding initial contents ->

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

    appending Pineapple to the end of the file ->

    echo "Pineapple" >> devops.txt

    verify/display ->

    cat devops.txt

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

    getting first three ->

    head -n 3 devops.txt

    reverse the order ->

    head -n 3 devops.txt | tac

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

    getting last three ->

    tail -n 3 devops.txt

    sorting in alphabetical order ->

    tail -n 3 devops.txt | sort

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

    creating file and adding content into ->

    echo -e "Red\nBlue\nGreen\nYellow\nOrange\nPurple\nPink" > Colors.txt

    display the content ->

    cat 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.

    creating file and adding colors in it ->

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

    prepend yellow on the top of the file ->

    sed -i '1s/^/Yellow\n/' Colors.txt

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

    sorting both the files ->

    sort fruits.txt > sorted_fruits.txt

    sort Colors.txt > sorted_colors.txt

    using 'comm' command to find the common lines ->

    comm -12 sorted_fruits.txt sorted_colors.txt

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

    for fruits.txt ->

    wc fruits.txt

    for colors.txt ->

    wc Colors.txt

The End of Linux Basic Commands

For more, subscribe