Unleash the Power of Linux: Commands with a Twist
View File Content with Line Numbers
Create a file:
touch file_name
Edit with Vim:
vim file_name
(Enter content, thenesc :wq
to save and exit)Display content:
cat file_name
Set File Permissions for Owner Only
Command:
chmod 700 file_name
Breakdown:
Owner: read (4) + write (2) + execute (1) = 7
Group/Others: no permissions (0)
Review Your Last 10 Commands
- Command:
history | tail -n 10
- Command:
Delete a Directory and Its Contents
- Command:
rm -r directory_name
- Command:
Create and Display a Fruits List
Create file:
touch fruits.txt
Edit file:
vim fruits.txt
Display content:
cat fruits.txt
Alternatively:
echo -e "Apple\nBanana\nCherry\nDate\nElderberry" > fruits.txt
Add and Append Content in devops.txt
Add content:
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
Append:
echo "Pineapple" >> devops.txt
Reverse the First Three Fruits
- Command:
head -n 3 devops.txt | tac
- Command:
Sort the Last Three Fruits Alphabetically
- Command:
tail -n 3 devops.txt | sort
- Command:
Create and Display a Colors List
- Command:
echo -e "Red\nPink\nWhite\nBlack\nBlue" > colors.txt
- Command:
Prepend "Yellow" to Colors.txt
- Command:
echo "Yellow" > temp.txt | cat colors.txt >> temp.txt | mv temp.txt colors.txt
- Command:
Find Common Lines Between Fruits and Colors
Sort files:
sort fruits.txt -o fruits.txt
andsort colors.txt -o colors.txt
Find common lines:
comm -12 fruits.txt colors.txt
Count Lines, Words, and Characters
- Command:
wc fruits.txt colors.txt
- Command: