EX200 Red Hat Certified System Administrator RHCSA – Essential tools for using Red Hat Linux and passing the exam Part 3

  • By
  • January 18, 2023
0 Comment

7. Vim text editor part 2. Making changes in the Vim text editor.

Welcome back everybody, to this tutorial. I’ll just go back into the text editor and today I want to show you how to search for things within a file. Okay, granted, you can actually do it as before by grabbing a certain word out of a file and looking at it there. But what we want to do today is find sort of a pattern within a file while we are editing the file. How to do that? Well, go ahead and bring up your command console. So just enter Insert mode by pressing Escape and then Colon. To get the command prompt. Go ahead and type in Slash and let’s search for a pattern is press Enter and you can see all of these patterns have emerged. You can find them all around. If you keep on pressing the letter N, the search will go to the next occurrence. So you see how the green cursor has moved to the first one and now it has moved to the second one, to the third one.

You can see how half of it is green and half of it is yellow in the third occurrence. And then we’re going to go to the fourth one and so on and so forth until we actually reach the end. And then we get the red warning mark. It says, hit the bottom, continue at the top. We got it the first time around because my cursor was down at the end, I think, or something of a kind. It doesn’t really matter if you just keep pressing in, if you press again, again, it’s just going to go back up and it’s going to spin around in a circle once more. But the search can go from top to bottom and from bottom to top. Keep that in mind. In order to conduct a search which will go from bottom to top, all you have to do is type in a question mark instead of a slash and then type in, I don’t know, let’s say letter i. There you go. I have indeed found my letter i.

And you see that the cursor now is at the first occurrence of letter I at the bottom. If I keep on pressing next, it’s going to start moving from bottom to top and it’s going to show me all the letter I’s. This is extremely useful, especially when you have a bit of a longer file and you’re looking for a specific thing within it. Then you can find those small, little tiny details that you are looking for by just using these search options. However, there’s also a very nice feature of navigation here within Vim, and that would simply be your ability to move your cursor as you wish without actually having to use the arrow keys. Let’s see what I mean precisely by it.

Let’s go ahead and do this now. If I wanted to, let’s say, go to the end of the line, you see where my cursor is it’s at somewhere or does it? That’s the beginning of the line. I’ll actually know. Building is on the right, sun is in the space. Well, sure it is. Everything has to be somewhere. That is the sentence that we are looking at it now. But actually there’s one even simpler up above. Never a dull day with you. So let’s take this one as an example. Look, I have not called my command prompt out. It is not there. I am simply in command mode now and suppose I want to go at the end of this line. What would I do? Well, you would just press a dollar sign on your keyboard and there we go. The cursor moves to the end immediately. If you press a carrot sign, it moves backwards immediately. You can keep pressing a dollar sign, a carrot sign and it’s going to shift between these two.

However, if you press a colon and if you type in dollar sign and press Enter, it’s going to throw the cursor to the last possible line. You can see that my cursor is now at this works at the last line. So dollar sign in the command line means end of file. It brings you to the end of file. It brings you to not to the end of file, but it brings you to the last possible line. While on the other hand, without the command line, if you just hit the dollar sign it will bring you to the end of the line. Now suppose you want to go back. I mean the obvious question here is, okay, I know how to get to the end of the line. Well, how do I get to the first line? Well, guess what, you just type in number one and your cursor is going to go to the first line. You can do this for any other line within the text. You can type in two or I don’t know, six or I don’t know, three. You see how the cursor is moving up and down when you specify the line, it goes there and it stays there. Now there is another interesting option here. It’s called joining the lines. So I’m going to go ahead and exit my please. Yes, okay, never mind. There we go.

Anyway, there’s a very nice option here which allows you to join the two lines. So let’s say that I want to join this one. With the next one, I would just use the dollar sign to get to the end and let’s use the J. So J will capital J will actually merge the line. So you see what I’ve done here. I have merged the two lines without bigger difficulty. I’ve just brought the cursor to the end of one line and I have merged it with the second line without I mean it wasn’t that hard, but there are a lot of these things to just keep in mind and remember. How would I go about undoing this thing, I would just press the letter U.

So just press letter U, that is, to undo. I guess you can already at the oldest change, you can just keep pressing the U to change stuff around to actually go backwards and backwards and backwards and backwards until you undo all the changes that you wanted. It says here down at the corner, at the bottom left corner already at all this change. Meaning that I haven’t really done anything to this file. And I really haven’t, other than just merged these two lines. But let’s just go ahead, let me just show you. If I did this and if I did this and I don’t know if I did this.

Excellent. Let’s just keep on pressing you now. One, two, three. There you go. I have managed to reverse the process completely and efficiently, so to say, without any difficulties whatsoever. It’s pretty simple. Just keep pressing you and all the steps. All the behemoth that you caused will be undone without greater difficulty. In any case, I would like to bid you all farewell and I sincerely hope that I will see you in the next tutorial.

8. Vim text editor part 3. How to search for text within a file.

Hello everybody, and welcome to this tutorial. Today I am going to show you how to search and replace within Vim. Before that, I have made a small file for myself. It’s called Vim, and I’m going to grab a line containing the word replace in it where I have written out the command syntax to explain. But take a look at this command that I’m using to pull this line from this file. Why on earth would I place the command clear in front of the cat command? There is nothing on my screen. Obviously, there is nothing in the terminal now, so why would I want to clear the screen in this fashion? Well, you see, what this will do is clear the command itself from the standard output of the screen. When you type in the command, you will only see the result of the command and not the command itself. Here’s what I mean by it. If I press Enter, there you go, the command has disappeared and I only have its output. If I didn’t do that, if I just typed in the regular cat, you see, it would remain on the screen. It would remain on the screen and you would be able to see the command and the output.

But the one that I have used with Clear simply states that the command will not be printed out to the screen. It will not remain on the screen. It’s a bit of a neat trick that I wanted to throw in here somewhere. Now, let us move on to the vim and replace. Within the replace, there is this first segment. So this here, this is the replace segment. You specify the command and you specify patterns to search, pattern to search and pattern to replace the search width. And then you can pass it in some additional arguments. But what we want to know now is these first three characters, what do they represent? If you remember from the previous tutorials I have mentioned, or I do believe that I have mentioned that the dollar sign represents the end. It will go to the last line, pretty much your cursor. If you type it into the command console of Vim, the dollar sign, the cursor will go to the last line immediately. And what is here? This is just line one, meaning go from line one to the last line. And in between, I want you to search a pattern and then replace that pattern with another one. Let’s go ahead and take a look at the file. Let me show you what I mean by this.

Notice how I have the numbers here. Quite simple. Just type in Seno, sorry, UPSUPS se no and you, they will disappear. And if I type in Senu, they will reappear. Excellent. So this will number the lines, which is a file, and then we will be able to get a better view of things. If I type in one coma ten. This is the range that encompasses the entire file. However, I can also type in one coma dollar sign, which is exactly the same thing. It encompasses the entire file as well. But you don’t want to always go to the last line and see which the last line is. And if you type in ten and if the file changes in size, the lines beyond ten will not be taken into consideration. To write the dollar sign at the end is a far more dynamic way of grabbing the entire file or saying basically that the entire file is a scope, but one, two and the last dollar sign is also equivalent to a percentage sign. But I think there we go. You can also type in percentage sign instead of one to dollar as that would definitely say pretty much the entire file.

However, we will deal with these signs a bit later on with more of them, I would say, as we move on into more complex commands. For the time being, I just want to show you the range and how you would specify the range. How would you use it and how would you utilize it with some other things. So let us type in one comma dollar sign, not space s. And now we shall select the pattern to search. I have already marked the Is pattern and I will type in Is excellent, is. And then another slash. Within the first slash you specify the pattern that you want to replace and within the second slash you will specify what do you want to replace it with? So I don’t know. Let’s type in what shall I type in here? What do I have on my desk? I have my phone. So let’s type in phone. And after the last slash you can actually pass in some additional options or arguments if you like one of those.

There are two things that I shall teach you how to do today, which is global and ignore case, which are probably the two most important ones. But if I just press Enter here, it says five substitutions on five lines. Does anybody see a problem here? Take a look at the 6th line. It says Building and then where it says Phone, there should be Is, but we have replaced Is with Phone. So it’s okay that it stands to reason that we have Phone now, but on the same line, the second Is pattern has not been replaced with Phone. What is the deal with this? What is the problem? Well, if you give the basic form of the command, it will only grab the very first pattern in the line and immediately after it does that, it’s going to move on to the next line. It’s not going to it will not care for the rest of the line. In order to avoid problems such as these, you can also you can use up and down arrows to list through the previous commands here, just so you know, after the last slash, you can type in G, which is global. Substitute all patterns is with phone, press Enter.

And there we go. All of the patterns now have indeed been substituted. But again, does anybody see another problem with this? Look at the year you have Is, but Is is written with a capital I. And the way we wish you the command this is not a corresponding pattern. This is something completely different to the computer and it does not care. However, we can tell it. I want you to ignore cases, ignore cases completely. So just pass the letter I, press Enter. You can pass in multiple arguments after Phone, after the last slash. And there you go. Now, the capital down. The letters here, which were capital letters, have indeed been replaced with the word phone as well. Fairly simple and the useful command to use, easier to get around. No problems, just keep on press escape file.

Let’s push undo, undo, undo, undo. There you go. Already at oldest change. So I have once again reverted back to the natural state of the file. So we call it the one that I have originally envisioned here. I’m going to cut the tutorial. I did you all farewell, a ton of I wish you a ton of luck and we shall see each other hopefully in the followup tutorial.

9. Vim text editor part 4.

Welcome back, everybody. Today I just want to give you three more commands, or four more commands to be more precise, before we actually call it today and move on to the next subject. However, before we get into VI, let me just show you something else over here in this terminal, notice how I have used the Cat command to pull certain lines from my Vim file. I have typed in the argument. I have passed the argument N to the Cat command, meaning that it should number all the lines. Then I have piped the output of Grab and I have piped the output of Cat and I have created the input for Grep. And with Grep, I have specified numbers. So four, five and six. Those were the numbers that I wanted to pull out of the file, meaning I want to pull the lines four, five and six. However, if any other line, for any other reason, anywhere within the line contained any of these numbers, that line would have been pulled as well. There is a better way of doing this. There is another command aside from Grep. It’s called E grab, more advanced version of Grab.

Take a look at man egrep and see what you can find there. There are some pretty interesting things here’s, how you would pull multiple patterns with egrep. So you would just type in pattern one, pattern two, and pattern three, or four, five, six. You can specify as many patterns as you like here and then you could pull it out of the file. So let me go ahead and type in six here, four here and five here. Excellent. So some of you might think, oh, well, you didn’t put them in the right order or something of a kind. The order is relevant, you can put it anywhere you like. It’s still going to pull exactly the same lines in exactly the same way. Anyway, let’s go ahead and go over the first command that I have listed here. It says delete a scope of lines. So there are no parameters here. This will just delete any given scope of lines. Let’s go ahead and open my other terminal. Press Escape to enter command mode. Go ahead and press Semicolon to get a command prompt.

Type in the range of lines, the scope of lines. So let’s type in four, two, six. We can use that one. We could have typed in anything else. We could have typed in one, two, eight and then deleted or whatever. I’m going to go ahead and say, I don’t know, six to eight, even though eight, only eight is practically blankets a space. It’s a new line. Let’s go ahead and type in six. Comma nine, delete. There you go. They have been deleted and you still see number six line here, right? Even though I have deleted it. No, it’s not the same line that we deleted, the lines have been deleted. Of that I assure you. You can rewind the tutorial. Or even better, here I can show you. The fact of the matter is that the numbers, that the line numbers have simply been rearranged. Nothing more. Let’s go press undo and type in semicolon. Again, let’s leave the same line.

So from six to nine. Take a look. They start with these words building somewhere. This one’s empty and this one begins with I. You will shortly see that none of these lines will actually be what you think they are, what they were, as they will be completely gone, delete. There you go, they’re gone. And you can see that none of these lines begins with any of those words. So undo the changes as we do need the file for a bit longer and then we can delete the whole file. Let’s go ahead and minimize this. The next command actually gives you a search option.

So it says Search and delete a pattern. Oh, I shouldn’t have written a pattern here. It’s basically search a pattern and delete a line containing that pattern. So let me just give you an example. Type in a semicolon here. Let’s give it a range. One, two, three. And then let’s search for a pattern to delete g. Let’s type in Sured. There you go. That line is gone. The line that contained sure is gone. You see that we have nine lines in total. Now, that’s complicated, right? Just type in these commands and you don’t need to know them all by heart. You just need to know some general logic and the rest will flow without bigger difficulties.

And to wrap it up, let’s just go ahead and use this last slide. But before I do, just so you know, vim has a lot of possibilities for commands. I mean a lot of possibilities. That is why it is so powerful. And that is why you should definitely also use all other online resources. Type in Vim space, regular expressions, examples or something of a kind. Press Enter and you will get a download of them because there are a lot of combinations with these regular expressions that you will need to do. And on Udemy in discussions, please, if you are having difficulties trying to do what you want to do with Vim, if you need me to help you out, just go ahead and post it in the discussions. I’ll be more than happy to help you out and to give you a proper regular expression to do whatever it is that you need to do simply because there are too many.

It would literally take ages. Or a tutorial whose length would be like a year, a year’s worth of tutorial to just cover Vim. But then again, nobody actually needs to know all of that. Nobody. You just need to know pretty much what I have taught you here and depending on what you want to do, perhaps a little bit more from the net. And that’s it. You’re good to go, no problems. But what I have taught you with Vim Qualifies, you more than enough to edit any file that you like, modify it, change it, save it, whatever. Anyway, let’s just go ahead and do the final command here. Let’s see what happens. So what can we do here? It says delete everything till the current line. The first number doesn’t need to be one. It can be whatever you want it to be. So you can say, I don’t know from line 50 till my current line where I am at the moment. I want you to delete everything.

So let’s just go ahead and open up this other terminal. So, same syntax as before. I’m just going to go and use from one to my current line and press Enter. There you go again. We have nine lines. It’s referring to the line where your current line is, where your cursor is at the moment. So I can move my cursor to Never and type in a semicolon. Again, use the same command, you will see that it’s going to be gone. I haven’t really moved my cursor that far, have I? Let’s just do a quick check, okay? Press escape and I’m going to move the cursor to the fourth line. So it’s 1234. We type in a semicolon and then use this pattern not found. We are doing the pattern again. I am terribly sorry.

You see this command that I am using now? It’s one coma dot. Means the search field will be from the first line, from the beginning of the document. So from here, this will be the beginning place. And then go to my current line, wherever my cursor is, my cursor happens to be here, I think. Let’s make sure it is there, shall we? Let’s put it on the fourth line. Okay, so it’s on the fourth line and press escape. Press colon. There we go. Anyway, what this says no, this is not the one.

Okay, there we go. What it says is go from the first line to where my cursor is at the moment, which is the fourth line. And I want you to search for sure for pattern shore for the word sure within that scope. As soon as you find it, delete that line. Simple as that. You’re just changing the scope, nothing else. This is a bit simpler to use because you can say not to go through the whole file. Just go to the portion of the file from anywhere to where I am at the moment and see if you can find it there. If you can, please delete that line and be done with it. Not that complicated. Just takes a bit of practice. That’s all that there is to it, nothing more.

Now I am going to go ahead and do all the press you a couple of times to make sure that my file, I have the original file. I’m going to type in WQ and then exclamation mark. You should know what this means by now. Means I’m going to write the file out, meaning save it q to quit it and exclamation mark. Don’t ask me any questions, please. I video farewell. Anyway, that would be the end of the tutorial here. I’m going to cut it and I hope to see you in the follow up tutorial where we will start dealing with files with file. System and how to manage files there I will give you the basic introduction into the file system of Linux which is very important for the basic understanding of how things work and it also helps to a very large extent to navigate and orientate yourselves primarily because you will know where is what or where can what be found. I did you farewell a lot of and I hope to see you in the followup tutorial.

Comments
* The most recent comment are at the top

Interesting posts

Everything ENNA: Cisco’s New Network Assurance Specialist Certification

The landscape of networking is constantly evolving, driven by rapid technological advancements and growing business demands. For IT professionals, staying ahead in this dynamic environment requires an ongoing commitment to developing and refining their skills. Recognizing the critical need for specialized expertise in network assurance, Cisco has introduced the Cisco Enterprise Network Assurance (ENNA) v1.0… Read More »

Best Networking Certifications to Earn in 2024

The internet is a wondrous invention that connects us to information and entertainment at lightning speed, except when it doesn’t. Honestly, grappling with network slowdowns and untangling those troubleshooting puzzles can drive just about anyone to the brink of frustration. But what if you could become the master of your own digital destiny? Enter the… Read More »

Navigating Vendor-Neutral vs Vendor-Specific Certifications: In-depth Analysis Of The Pros And Cons, With Guidance On Choosing The Right Type For Your Career Goals

Hey, tech folks! Today, we’re slicing through the fog around a classic dilemma in the IT certification world: vendor-neutral vs vendor-specific certifications. Whether you’re a fresh-faced newbie or a seasoned geek, picking the right cert can feel like trying to choose your favorite ice cream flavor at a new parlor – exciting but kinda overwhelming.… Read More »

Achieving Your ISO Certification Made Simple

So, you’ve decided to step up your game and snag that ISO certification, huh? Good on you! Whether it’s to polish your company’s reputation, meet supplier requirements, or enhance operational efficiency, getting ISO certified is like telling the world, “Hey, we really know what we’re doing!” But, like with any worthwhile endeavor, the road to… Read More »

What is Replacing Microsoft MCSA Certification?

Hey there! If you’ve been around the IT block for a while, you might fondly remember when bagging a Microsoft Certified Solutions Associate (MCSA) certification was almost a rite of passage for IT pros. This badge of honor was crucial for those who wanted to master Microsoft platforms and prove their mettle in a competitive… Read More »

5 Easiest Ways to Get CRISC Certification

CRISC Certification – Steps to Triumph Are you ready to stand out in the ever-evolving fields of risk management and information security? Achieving a Certified in Risk and Information Systems Control (CRISC) certification is more than just adding a prestigious title next to your name — it’s a powerful statement about your expertise in safeguarding… Read More »

img