Day 3 : 🖥️ Basic Linux Commands But with a Twist 🔄

Day 3 : 🖥️ Basic Linux Commands But with a Twist 🔄

·

2 min read

🚀 Today’s focus: mastering essential Linux commands 🖥️, but with a creative twist! Let’s turn the basics into powerful tools for problem-solving.

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

Cat -n hello.txt

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

Chmod 700 hello.txt

Task 3: Check the last 10 commands you have run.

history | tail -10

Task 4: Remove a directory and all its contents.

rmdir anjali (anjali is the directory/folder name here)

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

To Create file:- touch fruits.txt

To add content with Vim editor:- vim fruits.txt

To display content:- cat fruits.txt ( to display content with numbers add -n)

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

echo “Pineapple” » devops.txt

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

head -3 fruits.txt | tac

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

tail -3 fruits.txt | sort

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

Method 1:-

To Create file:- touch colors.txt

To add content with Vim editor:- vim colors.txt

To display content:- cat colors.txt ( to display content with numbers add -n)

Method 2:-

echo -e “Red\nBlue\nBlack\nGreen\nYellow\nPink\nWhite\nGrey” > colors.txt

Task 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

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

comm -12 <(sort colors.txt) <(sort fruits.txt)

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

wc fruits.txt colors.txt

Feeling more empowered with Linux now? đź’Ş Keep pushing your boundaries and exploring new ways to enhance your skills! Stay tuned for more exciting tasks ahead!

Â