Linux Basic Commands

Linux Basic Commands

⭐ Day 03 of #90DaysofDevOps

Hi Everyone, welcome to Day 03 of the #90DaysofDevops learning journey.

First, we will create one file file_day3.txt

cat > file_day3.txt

Welcome Cloud DevOps Journey

[Ctrl+d]     //press together to exit and save the content of a file.

🔸 To view what's written in a file.

syntax: cat <filename.ext> It will show the content of the given filename.

cat file_day3.txt

🔸 To change the access permissions of files.

Linux chmod command is used to change the access permissions of files and directories. It stands for change mode.

In the Linux file system, each file is associated with a particular owner and has permission access for different users. The user classes may be:

  • owner

  • group member

  • Others (Everybody else)

The file permissions in Linux are the following three types:

  • read (r)

  • write (w)

  • execute (x)

syntax: chmod <options> <permissions> <filename>

So in this example, we will give Owner Read Permission.

chmod 400 file_day3.txt   //read only permissins

🔸 To check which commands you have run till now.

The history command is used to view the previously executed command.

history

🔸 To remove a directory/ Folder.

  • The rm command removes complete directories, including subdirectories and files.

  • The rmdir command removes empty directories.

  • If you want to remove a directory and all its contents, you can use the 'rm' command with the '-r' option: rm -r <directory_name>

      rm demo1
      rmdir demo2
      rm -r demo3
    

Here in this day3 task created a directory demo1 in that demo1_file.txt. So now we want to delete the demo1 directory which contains the demo1_file.txt

It's not possible with the rm or rmdir command because it contains in demo1_file.txt

So we can remove the directory with the help of rm -r demo1

we can also delete multiple empty directories with the help of the rm command.

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

To create fruits.txt touch command.

touch fruits.txt   //create an empty file

Another way with the help of a cat command, you can also store data.

cat > fruits.txt
------Fruits List-----
1.Apple
2.Banana
3.Kiwi
<ctrl+d>
cat fruits.txt

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

echo -e "Apple \nMango \nBanana \nCherry \nKiwi \nOrange \nGuava" >> fruits_list2.txt

Here fruit_list2.txt file will be created new.

🔸 Show only the top three fruits from the file.

head Command: head command is a command-line utility, which prints the first 10 lines of the specified files. If more than one file name is provided then data from each file is preceded by its file name. We can change the number of lines the head command prints by using the -n command line option.

head fruit_list2.txt -n 3

🔸 Show only the bottom three fruits from the file.

tail command: It is a command-line utility that prints data from the end of a specified file or files to standard output.

tail fruit_list2.txt -n 3

🔸 To create another way to file colors_list.txt and view the content.

we can create files with the help of the vim editor.

Now, press i-->insert mode, which allows you to insert text into the file.

Now, press Esc :wq! -->save and quit, which allows you to forcefully save changes and exit the editor.

To view the content of colors_list.txt

cat colors_list.txt

🔸 Add content in colors_list.txt (One in each line) - Orange, Purple, and Grey.

🔸 To find the difference between the fruit_list2.txt and colors_list.txt files.

🎉 Task Done👍 Day 03 of #90daysofdevops 💯

In this article, we have covered the Day 03 task and some more Linux commands just as cat, chmod, rm, rmdir, touch, head, tail, diff, etc. As well as we have learned how to create a text file with the help of the vim editor.

If you enjoyed this article please like it and share it with your friends and colleagues!

Thank you for reading🤓