Basic Linux Commands for File Management

Irfan S MominIrfan S Momin
2 min read

Day 3 Task:

  1. To view what's written in a file.

    • cat filename

    • vim filename

    • nano filename

  2. To change the access permissions of files.

    • chmod 777 filename

  3. To check which commands you have run till now.

    • history

  4. To remove a directory/ Folder.

    • rm -rf filename

    • rmdir filename

  5. To create a fruits.txt file and to view the content.

    • touch fruit.txt - to create fruit.txt file

    • vim fruits.txt - to view content

    • cat fruits.txt - to view content

  6. 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 line

    • echo Banana >> fruits.txt add Banana word on the next line

    • echo Cherry >> fruits.txt add Cherry word on the next line

      or use a line command like below

    • echo -e "Apple \nBanana \nCherry \nKiwi \nOrange \nGuava \nMango \nWatermelon" >> fruits.txt

  7. Show only the top three fruits from the file.

    • head -3 fruits.txt

  8. Show only the bottom three fruits from the file.

    • tail -3 fruits.txt

  9. Create another file Colors.txt and view the content.

    • touch Colors.txt - to create Colors.txt file
  10. 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

  11. Find the difference between the fruits.txt and Colors.txt file.

    • diff Color.txt fruits.txt compare files line by line

1
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