Day 3 Task: Basic Linux Commands with a Twist
Learn and Use Basic Linux Commands Today
View the content of a file and display line numbers.
$cat -n filename
Change the access permissions of files to make them readable, writable, and executable by the owner only.
$chmod +x filename
Check the last 10 commands you have run.
$history | head -10
Remove a directory and all its contents.
$rm -R /pathofdirectory
Create a
fruits.txt
file, add content (one fruit per line), and display the content.$touch fruits.txt $echo "Pineapple" >> fruits.txt $echo "Banana" >> fruits.txt $echo "Apple" >> fruits.txt $echo "Grapes" >> fruits.txt $echo "Guava" >> fruits.txt $echo "Orange" >> fruits.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.$touch devops.txt $echo "Banana" >> fruits.txt $echo "Apple" >> fruits.txt $echo "Orange" >> fruits.txt #Append pineapple at the end of the list $echo "Pineapple" >> fruits.txt
Show the first three fruits from the file in reverse order.
$sort -r fruits.txt
Show the bottom three fruits from the file, and then sort them alphabetically.
$sort fruits.txt $sort fruits.txt | tail -3
Create another file
Colors.txt
, add content (one color per line), and display the content.# we can add content vy using vim editor also: $vim colors.txt # we can use echo command as well $echo "Green" >> fruits.txt $echo "Pink" >> fruits.txt $echo "Red" >> fruits.txt $echo "Orange" >> fruits.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.# Prepand "Yellow" to the begining of the file $sed -i '1i Yellow' colors.txt $cat colors.txt
Find and display the lines that are common between
fruits.txt
andColors.txt
.comm -12 sorted1.txt sorted2.txt
Note - Before giving comm command make sure your comparison file must be sorted.
Count the number of lines, words, and characters in both
fruits.txt
andColors.txt
.# How to find word count, character count and line count $wc -c colors.txt $wc -l colors.txt $wc -w colors.txt