Basic Linux Commands for File Management


Day 3 Task:
To view what's written in a file.
cat filename
vim filename
nano filename
To change the access permissions of files.
chmod 777 filename
To check which commands you have run till now.
history
To remove a directory/ Folder.
rm -rf filename
rmdir filename
To create a fruits.txt file and to view the content.
touch fruit.txt
- to create fruit.txt filevim fruits.txt
- to view contentcat fruits.txt
- to view content
Add content in fruit.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
echo Apple > fruits.txt
add Apple word on the first lineecho Banana >> fruits.txt
add Banana word on the next lineecho Cherry >> fruits.txt
add Cherry word on the next lineor use a line command like below
echo -e "Apple \nBanana \nCherry \nKiwi \nOrange \nGuava \nMango \nWatermelon" >> fruits.txt
Show only the top three fruits from the file.
head -3 fruits.txt
Show only the bottom three fruits from the file.
tail -3 fruits.txt
Create another file Colors.txt and view the content.
touch Colors.txt
- to create Colors.txt file
Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey.
echo Red > Colors.txt
echo Pink >> Colors.txt
echo White >> Colors.txt
or use a line command like below
echo -e "Red \nPink \nWhite \nBlack \nBlue \nOrange \nPurple \nGray" >> Colors.txt
Find the difference between the fruits.txt and Colors.txt file.
diff Color.txt fruits.txt
compare files line by line
Subscribe to my newsletter
Read articles from Irfan S Momin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Irfan S Momin
Irfan S Momin
A Foodie Software Engineer's Journey to Eating Healthy and Learning Something New Every Day