Day 3 - Mastering Essential Linux Commands: A Practical Guide for Beginners (29 Nov, 2023)

Day 3 Task: Basic Linux Commands
Task: What is the linux command to
To view what's written in a file.
To change the access permissions of files.
To check which commands you have run till now.
To remove a directory/ Folder.
To create a fruits.txt file and to view the content.
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
To Show only top three fruits from the file.
To Show only bottom three fruits from the file.
To create another file Colors.txt and to view the content.
Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
To find the difference between fruits.txt and Colors.txt file.
To view what's written in a file:
cat filename
To change the access permissions of files:
chmod permissions filename
Replace
permissionswith the desired permission code (e.g., 755) andfilenamewith the actual file name.To check which commands you have run till now:
history
To remove a directory/Folder:
rmdir directory_nameor
rm -r directory_name
To create a fruits.txt file and view the content:
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > fruits.txt cat fruits.txt
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava": This part of the command uses theechocommand to print the specified string to the terminal. The-eoption enables the interpretation of backslash escapes in the string. In this case,\nrepresents a newline character, so each fruit name is on a new line.> fruits.txt: This part of the command uses the output redirection operator (>) to redirect the output of theechocommand to a file namedfruits.txt. Iffruits.txtalready exists, it will be overwritten with the new content. If it doesn't exist, a new file will be created.
To add content in devops.txt (One in each line):
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
To show only the top three fruits from the file:
head -n 3 fruits.txt
To show only the bottom three fruits from the file:
tail -n 3 fruits.txt
To create another file Colors.txt and view the content:
echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt cat Colors.txt
To find the difference between fruits.txt and Colors.txt file:
diff fruits.txt Colors.txt

This will display the lines that differ between the two files. If there's no output, the files are identical.




