#devops DAY3

Technology Linux HD Wallpaper | Background Image

Hello, everyone, this is my third blog and also my second DevOps class. From this blog, I want to share my Second-day experience OR some information on Linux with you. #linux #trainwithshubham #shubhamlondhne

INTRODUCTION TO BASIC LINUX.

Lists of contents.

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

  2. To change the access permissions of files.

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

  4. To remove a directory/ Folder.

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

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

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

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

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

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

  11. To find the difference between fruits.txt and Colors.txt files.

LETS START WITH SOME INTERESTING INFORMATION

To view what's written in a file.

A command-line interface is offered by Linux and can be used to open files using different commands. Other common file extensions are also supported by the program. The following file commands help open files from the terminal:

The command of the cat It is possible to concatenate, display, and create files on the terminal with the cat command in Linux. Without actually opening the file in a text editor or file manager, the contents of a whole file may frequently be seen on the terminal window with the cat command. It uses the default editor and outputs the contents of the file to standard output. "CAT <Filepath>"

To change the access permissions of files.

Using the chmod command, you can modify a file's access permissions in a Unix-like system (like Linux or macOS). You can change the read, write, and execute permissions for the owner, group, and others with the chmod command.

To add permissions, type chmod +rwx filename. To revoke permissions, type chmod -rwx directory name. To provide executable permissions, type chmod +x filename. chmod -wx filename will remove the executable and write permissions. Keep in mind that "r" stands for read, "w" for write, and "x" for execute.

To check which commands you have run till now.

A common built-in command in Unix-like operating systems, such as Linux and macOS, is the history command. It enables users to view a history of commands that have already been run in the current terminal session. The command history records the commands you've entered throughout the current session, making it simple for you to recall and reuse them.

The history command shows a numbered list of commands when you run it, often with the newest commands at the bottom and the oldest commands at the top. You can utilize the individual number provided for each command to carry out or repeat a particular command from the history.

To remove a directory/ Folder.

To remove a directory, use the rm (remove) command in the Terminal. The syntax is as follows:

Explanation:

-r - Recursively remove directories and their contents.

-f - Forcefully remove directories without prompting for confirmation.

Replace "path_to_directory" with the actual path of the directory you want to remove.

And also we use {rm -a (file path)} for deleting files or directories.

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

Sure! Here are the steps to create the fruits.txt file and view its content in Linux using command-line tools:

  1. Open a terminal:

    • You can open a terminal by pressing Ctrl + Alt + T on your keyboard or by searching for "Terminal" in your applications.
  2. Create the fruits.txt file:

    • To create the fruits.txt file, you can use the touch command, which creates an empty file. Type the following command and press Enter:

This will create an empty fruits.txt file in the current directory.

  1. Open the fruits.txt file with a text editor:

    • To view and edit the fruits.txt file, you can use a command-line text editor like vim or vi. In this example, we'll use vim. Type the following command and press Enter:

The vim text editor will open with an empty file named fruits.txt.

  1. Add fruits to the file:

    • In the vim editor, type the names of fruits, each on a separate line. For example:

Use the arrow keys to move the cursor and make any edits you want.

  1. Save the file and exit vim:

    • To save the changes, press Ctrl + O (the letter O, not zero), and then press Enter.

    • To exit vim, press Ctrl + X.

  2. View the contents of fruits.txt:

    • To view the contents of the file, you can use the cat command in the terminal. Type the following command and press Enter:

The cat command will display the contents of fruits.txt in the terminal, showing the fruits you added.

That's it! You have now created the fruits.txt file, added fruits to it, and viewed its contents in Linux using the vim text editor and the cat command.

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

You can use the echo command and the >> redirection operator in the console to add the material you supplied to the devops.txt file with each fruit on a separate line. Here is how to go about it:

Use the echo command to output data or display messages in the terminal.

  • echo: The echo command is used to display messages or output data in the terminal.

  • -e: This option enables the interpretation of backslash escapes, allowing us to use \n to represent a new line.

  • "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava": This is the content you want to add, with each fruit on a separate line.

  • >> devops.txt: The >> Redirection operator is used to append the output of the echo command to the devops.txt file. If the file doesn't exist, it will be created.

Show only the top three fruits from the file.

Using the head command on the terminal, you can limit the display of the devops.txt file to the first three fruits. The top (starting) part of a file is shown with the head command. You can choose how many lines to display; by default, it displays the first 10 lines of the file. In this instance, the top three lines (fruits) should be displayed. Here is how to go about it:

  • head: The head command is used to display the beginning (top) portion of a file.

  • -n 3: This option tells the head command to display the first 3 lines of the file.

  • devops.txt: This is the file name from which you want to display the top three fruits.

Show only the bottom three fruits from the file.

Use the tail command on the terminal to display the devops.txt file's bottom three fruits only. The bottom (end) part of a file is shown using the tail command. You can choose how many lines to display; by default, it displays the latest 10 lines of the file. In this instance, we want to show the fruits along the bottom three lines. Here is how to go about it:

  • tail: The tail command is used to display the end (bottom) portion of a file.

  • -n 3: This option tells the tail command to display the last 3 lines of the file.

  • devops.txt: This is the file name from which you want to display the bottom three fruits.

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

To create the Colors.txt file and view its content on Linux, you can use the terminal. Here are the steps:

  1. Open a terminal:

    • You can open a terminal by pressing Ctrl + Alt + T on your keyboard or by searching for "Terminal" in your applications.
  2. Create the Colors.txt file:

    • To create the Colors.txt file, you can use the touch command, which creates an empty file. Type the following command and press Enter:

This will create an empty Colors.txt file in the current directory.

  1. Open the Colors.txt file with a text editor:

    • To view and edit the Colors.txt file, you can use a command-line text editor like nano or vi. In this example, we'll use nano. Type the following command and press Enter:

The nano text editor will open with an empty file named Colors.txt.

  1. Add colors to the file:

    • In the nano editor, type the names of colors, each on a separate line. For example:

Use the arrow keys to move the cursor and make any edits you want.

  1. Save the file and exit nano:

    • To save the changes, press Ctrl + O (the letter O, not zero), and then press Enter.

    • To exit nano, press Ctrl + X.

  2. View the contents of Colors.txt:

    • To view the contents of the file, you can use the cat command in the terminal. Type the following command and press Enter:

The cat command will display the contents of Colors.txt in the terminal shows the colors you added.

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

To add the content you provided to the Colors.txt file with each color on a separate line, you can use the echo command and the >> redirection operator in the terminal. Here's how you can do it:

Explanation:

  • echo: The echo command is used to display messages or output data in the terminal.

  • -e: This option enables the interpretation of backslash escapes, allowing us to use \n to represent a new line.

  • "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey": This is the content you want to add, with each color on a separate line.

  • >> Colors.txt: The >> redirection operator is used to append the output of the echo command to the Colors.txt file. If the file doesn't exist, it will be created.

After executing this command, the Colors.txt file will contain the following content:

Each color is on a separate line as specified in the echo command. The colors have been successfully added to the Colors.txt file.

To find the difference between fruits.txt and Colors.txt files.

You can use the diff program in the terminal to determine the differences between the fruits.txt and Colors.txt files. Using line-by-line comparison, the diff tool shows the differences between two text files. Here is how to go about it:

If there are any variations between the contents of Fruits.txt and Colors.txt, this command will show them in the terminal output. If there are no differences, there won't be any output from the command.

The diff program will display differences between the two files in a particular format if there are any. Lines beginning with a signify lines that are present in fruits.txt but not in colors.txt, and lines beginning with a > signify lines that are present in both colors.txt and fruits.txt but not in either.

THIS IS A SOME BASIC INFORMATION ABOUT LINUX.

THANK YOU FOR WATCHING THIS BLOG AND THE NEXT BLOG COMING SOON