Day 3 : Basic Linux Commands

Day 3 : Basic Linux Commands

  • Cat command : Cat command is used to display contents of the file

For example here we are using echo command to write/print "Hello World" in the file where in our first file which is called as first.txt to create our first file we use > sign .
Now using cat command we will display contents in the file in our case it is Hello World.

  • To change Persmission of File : (chmod) :- This command is used to change the permission of the file. For this you should be either superuser or Admin to change its respective permissions.

  • Basic syntax of chmod is : chmod [option] [permission] [file_name]

  • chmod 777 first.txt

777 : All users can read,Write and execute the file

775 : command will grant the read, write, and execute permissions to the owner of the file or directory and to the group associated to it.

  • To check which commands you have run till now

  • history : history command is used to check which commands you have run till now.

  • To remove a directory/ Folder

  • To remove a directory/folder use rm command

  1. Option to confirm before deleting each file use : rm -i file_name

  2. To remove files without prompting use -f (here -f is nothing but forcefully remove those files/directories) : rm -f file_name

  3. To remove non empty directories/files without being prompted you can use -rf : rm -rf file_name

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

We are using touch command to create fruits.txt and to display contents from that file we will be using cat command

  • Add content in fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava

To add contents in fruits.txt we will use vim command , so vim fruits.txt

press enter after that you will redirected to terminal press i to write the fruits name as

Now type all the fruits name as shown below , once you are done press escape and hit : and type wq that will save your file and you will be prompted to the terminal .Now to view contetnts of the file use cat command again

  • To Show only top three & bottom three fruits from the file.

  • To show top three fruits we will be using head command to display top 3 fruits . Similalry we will use tail command to display bottom 3 fruits from the file such as:

  • To create another file Colors.txt and to view the content

  • Similarly to create colors.txt we will follow the same set of commands

  • touch colors.txt

  • To display contents of that file we will use cat colors.txt

  • Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

Now lets add more contents to the file using the following commands

  • To view contents of the file we will use cat command again as

  • To find the difference between fruits.txt and Colors.txt file

  • To find differnece between two file we will use diff commands

To learn more linux refer this video

Did you find this article valuable?

Support Akshay Phadke by becoming a sponsor. Any amount is appreciated!