Essential Linux Commands with Unique Tips #Day-3
Must-Know Linux Commands and Rarely Known Tips
Table of contents
- View the content of a file and display line numbers:
- Change the access permissions of files to make them readable, writable, and executable by the owner only:
- Check the last 10 commands you have run:
- Remove a directory and all its contents:
- Create a fruits.txt file, add content (one fruit per line), and display the content:
- 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:
- Show the first three fruits from the file in reverse order:
- Show the bottom three fruits from the file, and then sort them alphabetically:
- Create another file Colors.txt, add content (one color per line), and display the content:
- 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:
- Find and display the lines that are common between myfruits.txt and Colors1.txt:
- Count the number of lines, words, and characters in both myfruits.txt and Colors1.txt:
- Conclusion
Linux commands are powerful tools that enable users to interact with the operating system efficiently. Here are some essential commands along with unique tips to make the most out of them:
View the content of a file and display line numbers:
nl filename
nl day3.txt
Change the access permissions of files to make them readable, writable, and executable by the owner only:
chmod 700 filename
chmod 700 day3.txt
Check the last 10 commands you have run:
history | tail -n 10
Remove a directory and all its contents:
rm -r directory_name
rm -r directory_name
Create a fruits.txt
file, add content (one fruit per line), and display the content:
echo -e "Kiwi\nWatermalon\nPinepal\nCherry\nGrep\nOrange" > myfruits.txt
cat myfruits.txt
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 -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
echo "Pineapple" >> devops.txt
Show the first three fruits from the file in reverse order:
head -n 3 myfruits.txt | tac
Show the bottom three fruits from the file, and then sort them alphabetically:
tail -n 3 myfruits.txt | sort
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
cat Colors.txt
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 "Yellow" | cat Colors.txt > temp && mv temp Colors1.txt
cat Colors1.txt
Find and display the lines that are common between myfruits.txt
and Colors1.txt
:
comm -12 <(sort myfruits.txt) <(sort Colors1.txt)
Count the number of lines, words, and characters in both myfruits.txt
and Colors1.txt
:
wc myfruits.txt Colors1.txt
Conclusion
Mastering essential Linux commands can significantly enhance your efficiency and productivity when interacting with the operating system. By understanding and utilizing these commands, you can perform a wide range of tasks, from viewing and editing files to managing permissions and directories. The unique tips provided in this guide aim to help you leverage these commands to their fullest potential, making your Linux experience more streamlined and effective. Whether you are a beginner or an experienced user, these commands are fundamental tools that can simplify your workflow and improve your overall command-line proficiency.
Connect and Follow Me On Socials :
Like👍 | Share📲 | Comment💭