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

  • By
  • January 18, 2023
0 Comment

4. I/O Redirection part 2. Redirect standard error to standard output or command.

Welcome all. Today I am going to talk a bit about standard errors and how to redirect them. So you would redirect the standard error with number two and a greater than sign. Simple as that. Now, this is a bit of a tricky area, primarily because you do actually need to cause some errors to happen. And if I may say so, I am an absolute master at this. I can cause errors pretty much anywhere. Anyhow. They do happen to me anyway. They happen to all people who deal with these sort of things, who are network admins, who will encounter a download of them, of that I assure you. Anyway, let’s go ahead and type in LS and then give some nonsensical path to LS, which has no connection to reality of whatsoever. And then redirect this. Just press Enter and then you will see that the output is actually an error message. It says, LS cannot access this nonsensical path.

That is right here says no such file or directory. Okay? So we don’t want to see that for the time time being. We will redirect this to redirect this to let’s call it err as an error. There you go. Nothing has been printed out to the screen. But if I type in Cat er, press enter. There you go. The error has actually successfully been redirected to a file. Now, this is not a very practical example, is it? I mean, it’s completely pointless because we want to see this error message unless we wanted to save it to a file and then analyze it later or something of a kind or log it.

But in general, not a very practical example. Let’s see if we can do something else. Let’s see if we can come up with a more meaningful error message. Type in go to root and type in Find. We’re going to get a ton load of error messages. Name, type in whatever you want here you can literally smash your keyboard. Excellent. So we have gotten a ton load of permission denied messages and I don’t think this is going to be fine. We’re not going to find this anywhere. So let’s type in something more meaningful. But I just want to show you that you’re getting a lot of meaningless error messages primarily because you don’t want to find reporting that there is a permission denied somewhere or something of a kind. You know, what you want to search for and you are a regular user.

Obviously you won’t be able to access route directories, root directory or something of a kind. You won’t be able to access maybe look, you have folder specified here. It’s VAR TMP system MD private. Let me just show you what I mean by that. There we go. This one and the ones that followed it and preceded you won’t be able to access something of a kind and therefore, you know, you do not want to be searching for it in there. But if you’ve typed in Find, as I have in the root, that can be a problem because it’s just going to go through all of these things.

And of course you can limit it by specifying a folder, but you can also omit all. Permission denied. What are we going to do? We are going to say find name. Let’s just clear the screen for simplicity’s sake. Find name space test and we’re going to do two and then redirect to home because we won’t be able to save it here. Err, excellent. Press Enter and there we go. It has actually located test file name test without displaying all those useless error messages here. This is very convenient and very practical. Just compare these two outputs.

Seriously, take a look. I’m sure you could find amongst these infinite error messages that test has been found somewhere and I could scroll upwards until infinity. Give you a bit of a headache, I suppose. However, I’m not going to do that anyway. Let’s just clear the screen and come back to this file. It’s fine. Namespace test to greater than and then we use a shortcut in order to access a file in our home directory. Shortcut is tilda, a shortcut for the current user’s home directory. However, we can also do the following. I mean, we can redirect the results, the legit results into a file as well. But there is an important concept here to understand. If you want to redirect standard error, you should always, and I mean always use it last. That’s how it works. So let’s go ahead and type in greater than sign to tildefound and then type in two greater than sign space tilde.

Err, what we are doing here, we are redirecting standard output to a file and we are redirecting standard error to a different file as well. Okay, so not a new concept, not an original concept, but the important thing to remember here is that you have to use redirection of the standard error last. Press Enter and there we go. So if I just do catfound there we go. We have all of these things listed out here for us and now we can have a look at them, filter them, process them, do whatever you want with them. Doesn’t really matter if the file belongs to you, you own it, you are its master and you are omnipotent. In that sense, that would be it for standard error. Now, in the later tutorials, I’m not going to be dealing specifically with standard error, but we are going to be using redirections in general. And you will see how these things come to play when you are typing in.

Larger commands. Longer commands, should I say? And when doing more complex stuff, the combining will come, will be mentioned somewhere along the way, as we will definitely need to use it. By that I mean combining standard error and standard output into one and redirecting one to the other, and so on and so forth. However, keep in mind that these are still some of the basic concepts of Redirection, and I haven’t really used them in any complex way or something of a kind. Probably the most complex command that I have used thus far is the one in the previous tutorial. But for the time being, I just want you to get acquainted with these concepts. Please know them as if you don’t. If you fail to actually just memorize these three simple concepts, they will hinder you along the way. So standard output, actually standard input, standard output and standard error. Keep them in mind. Those are the three channels that you can use. Those are the three channels that pretty much all commands have, and they are quite important. I cannot emphasize this enough. Sorry if I’m being a bit tedious or something of a kind, but believe me, it is for a very good reason. Anyway, I’m going to go ahead and bid you all farewell and I hope to see you all in the next tutorial. Where we shall deal, where we shall further our understanding of Red Hat and of Linux Terminal in general.

5. I/O Redirection part 3 for redirecting standard error in more depth.

Welcome all to this tutorial. Today I am going to talk about text editing and text editors in general. I myself tend to use two to three text editors. One would be for graphics mode, that would be g edit, or not just g edit, actually depending on the version of desktop that I’ve installed. But that doesn’t really matter to you. What matters to you are these terminal text editors. Primarily because you will be dealing with a large amount of configuration files that you will need to edit from within your terminal. This is a very nice feature that you have in Unixlike systems that you are able to edit all files in the terminal. You have nano, which is fairly simple. I do believe that it does come pre installed, but it’s way too simple for what we needed. Rather instead, what is a general text editor that pretty much everybody uses and that you can rest assured is installed by default on every Unix Linux like system. And I’m not just referring to the servers or to the desktop or to the Linux desktops or something of a kind. But rather instead if you log into your routers via SSH or something of a kind, you will see that you do actually have a VI text editor installed there.

So there is VI and there is Vim. Vim is simply the next version of VI. It’s an abbrevation. It stands for VI. Improved. Anyway, all of these more devices, compact ones, such as routers, something of a kind, most of them will have VI installed on them, which you can use to edit files and stuff like that, depending on what sort of router it is. But more importantly for you, as I’ve said, you will need VI editor in order to edit all sorts of files in Linux, in order to change the configuration and so on and so forth. But look, VI is not very user friendly, that’s for sure. Everybody out there agrees on this particular matter. It is definitely not user friendly, but it is quite powerful and you can do a great deal with it. Let me just go ahead and start VI. Basically to edit a file, you would just type in Vim space or just VI depends. But mostly now people just use Vim. Vim and then you would type in the name of your file. I’m going to use my sample text. Is it here? It’s called my sample text.

Sorry, V-I-M my sample text. Now this file is already created and I have created some random text in it. Took me a while to actually write that text for you. But look, let’s say that it wasn’t created at all, that there was no file, my random text or anything of a kind. My Sample text, you could actually type in the name of the file here. So name of the file and Vim would actually create the file if you didn’t save it. Nothing would happen of course but by the time if you did this, opened it, add some text, did something to it and then saved changes, the file would be created of course as before, you can also add path here so path file anyway, you can also create a path here and create a file and edit it anywhere on your file system. So anywhere, it doesn’t matter, you can just set the path.

As long as you have the right permissions, you will be able to do it. But for the time being, let’s go ahead and open up this file. So my sample text, I know it’s an awesome text. Anyway, it’s just a random text that I have created for the purposes of this exercise because we needed some text form. So we can manage it, edit it, change it, we can search through it, et cetera. Now, VI vim has two basic modes. One mode is insert and another one is command. So for command mode you would just type in I am currently in my command mode and if I want to pass in, I can press certain buttons in a keyboard which will cause things to happen. We will go over this, but I can also go ahead and press semicolon. Sorry, I can also go ahead and press semicolon and you can see that the bottom changes. Let me just show you what I mean by it. Okay? So once again, please monitor the bottom of the screen. I press semicolon and there you go. Now I can type in commands here. Notice this is not a text which will be added to the file or something of a kind. Although you can’t pass such commands. This is just a command mode which where we issue commands to Vim in order for us to perform certain tasks such as save things. So if you want to save something, you would press W.

If you wanted to quit, you would press Q or something like that. These commands that you pass the VI M can be extremely simple like single letter commands that I am passing here or they can be literally several lines long. It all depends on what you are doing, although you’re not going to have one that’s several lines long. That’s just a theoretical thing. You might have a kind of a complex command which is maybe one line long or something of a kind when you’re searching for some extremely complex patterns or you’re doing some complex filtering. But for your day to day average usage as a network administrator, you’re not going to be basically compelled to do stuff like that. You will mainly just use Vim in order to edit file, change things, send them, perhaps find something, so on and so forth. Anyway, let’s go ahead and deal with another mode.

You would basically press escape to pretty much cancel this colon so that the VI would no longer be accepting commands. And now if I wanted to enter Insert Mode, where I can type things into the term, into the file, I would just press I and you can see that the bottom changes again. It states that I am in effect now in the Insert Mode. And in the insert mode, I can type in whatever I want. So whatever I want shall be done. Anyway, you can see that I can type in now whatever I want, but if you exit Insert Mode, you won’t be able to type in anything. I’m pressing the keys on my keyboard, but I’m not getting the reaction that I want to get. Nothing is being typed in.

So I hope you learned basically in this particular tutorial, just three things that I want you to remember. You have Insert Mode, you have Command Mode, and you have sort of two versions of the Command mode, where you don’t have the semicolon down below, where you’re not typing in commands, where you just press a letter on your keyboard, which I will show in the follow up tutorial. Several things there and you cause a reaction. For example, you could go to the I don’t know, you could move the cursor to the end of the file or something of a kind, but you will be able to do this from the command line as well and summon the command line. Semicolon. Sorry, just type in the semicolon and type in the command here. So, three things. Insert command mode. Two types of command. Either a semicolon here, where you type in the commands, or where you just kind of press the buttons and you get to cause a reaction. Anyway, I bid you all farewell and I hope to see you in the follow up tutorial.

6. Vim text editor part 1. How to do text editing and use text editors.

Welcome back, everybody. We’re just going to go ahead and continue with Wim. So now we are within this file. We have indeed opened it and suppose we want to change something. Okay, so as I showed you before, just press I and you will enter Insert Mode. I have added one line at the end. Whatever one shall be done. It’s a bit of a bit of a selfish thing to say. Narcissistic, I suppose even. But just a joke. Anyway, so if I just separate it like this so we can see it better, how would I save it? What would I do to exit a program and save it? Well, let’s go ahead and exit the Insert mode because we need to enter the command mode for this and type a colon in order to get a prompt to enter commands. So suppose I want to quit. What command have we used to quit programs thus far? Well, just pressing either Q or CTRL C seemed to be doing the trick. So let’s try Q. Press q enter. Oh, it says Error 37 no rights since last change. Add exclamation mark to override. Now, remember me saying that vim is not user friendly? Try reading this red message down below and try to figure out what it actually means. It says no rights since last change. The sentence actually is referring to the fact that we have saved nothing and that we have changed a file to an extent and we haven’t really saved those changes. So it is denying us, it is refusing to exit the program because if it does, those changes will be lost.

And it is also telling us that we can add an exclamation mark at the end in order to override this and to exit anyway. So let’s actually try to do that before we do any saves in general, in Linux and Unixlike systems, write usually means save in a lot of instances. Okay, let’s go back. If you don’t know how to exit this red error message, just press Colon again. That’s all you need to do. No big deal. Very well, let’s press Q and then exclamation mark. Press Enter. There you go. We have managed to successfully exit the program. However, if I go back into the file, you will see that the last line is gone, no longer there. Let’s go back into the Insert mode and conduct some changes. I am changing you. Excellent. Press escape to exit. Insert mode. Press Colon to Enter Command to actually get the command prompt. And now we’re going to try typing in again Q. If we press okay, so this time we will do something different. This time, instead of actually just overriding the error, we’re going to go ahead and do the right thing and save the file. So just type in W to write and there you go.

It says, my sample text written it is now in effect, saved. And if I just press Q again. I have successfully exited the program once again. Let’s go back in. You see, it has been saved. All the changes have been written. Now, there is another thing that you can do here. You don’t actually need to write W and then Q. Rather instead you will be able to write something of a kind like WQ. So write and then quit. Excellent. There we go. Let me just show you that this works. I need to go back into search mode. Enter. This works escape colon WQ enter, get back into the file. There you go. You see that it has indeed saved that. You don’t need to do the commands individually. Rather instead you can just chain as many of them as you like in a stream in a row and it’s going to work.

Also, you can do something like this WQ exclamation mark. This is what people usually do like WQ exclamation mark. This exclamation mark literally means do not ask me anything. I don’t care, I don’t want to know. Just do whatever I told you and shut up. I suppose that’s one way of looking at it, but not a very good idea. You want to get those error messages. They are there for a reason. Okay, so let’s delete these two and let’s see what we can do about copy, paste and cut. There we go. Just press Escape to exit the command line. You know how in text editors thus far, if any of you have used Word or something of equivalent, you know how you can actually cut a sentence or cut a letter or something of a kind, or cut a chunk of text from the file and then paste it elsewhere within the file? Well, here you can do the same thing, no worries. But it’s not as simple because you don’t have the mouse. I mean, you have to do it all with the keyboard. So how would you do this with the keyboard? Well, simple enough. Select the line that you would like to cut. Let’s select the line. I do not know. The Red Riding Hood passed by. That is never good.

I have no idea why I wrote that. There we go. I have deleted or cut the line. You just press the letter D as in donkey or destination or something like that. So just press letter D as in destination twice so DD and have your courser on the line that you want to cut or delete. If I go down to the bottom oops, I need to go back into insert mode. I can press P and there you go. I have pasted the file. There is also another thing that you can do that you do not need to actually cut the line or anything like that. You can yank it. And yanking is basically copying. A bit of difference in terms, I suppose, but just press double Y. So Y as in U year or something of a kind. Just press y twice quickly. I have copied it. Now I’m going to go ahead and paste it. There we go. I have pasted it without copying it or deleting it or doing something of a kind. It’s a literal copy. So DD can be used to either delete a line or to cut it. Once you press DD, it is stored in a buffer until something else happens.

And this you should keep in mind, because if you want to cut two lines and paste them somewhere, if you cut one and then you cut the other, you’re just going to have the other one in the buffer. You’re not going to have the first one. That can be a bit problematic. Anyway, we’ve done cut, copy and paste. But suppose you wanted to grab a couple of lines. Suppose you wanted to do more than one single line and you wanted to take it, copy it, cut it, paste them, whatever. Well, here’s what you would do. You would place a cursor somewhere, type in well, let’s put it here. Let’s say three DD. What just happened? Can you see? Let me show you one more time based. I have one follow the cursor. So, one, two, three. I have typed in the number three here. Let me just show you. In the command line, I’ve typed in the number three and I’ve typed in DD, meaning I want you to cut three lines from the cursor downwards, including the line where the cursor is. Very simple.

This can be used with Yankee as well. So just type in three number. Here you can put 34. 348. You can cut 348 lines from the cursor downwards and you can yank them in order to copy them elsewhere. When pasting, you don’t actually when you want to paste them back, you don’t actually need to specify any numbers. You can just type in letter P and the lines will be pasted. So, to paste its P, to cut its DD, to copy its YY, very simple. Three commands. The point of this tutorial was to teach you practically these three commands. You can type in numbers instead. You can type in numbers in front of YY and DD. So you can cut and copy as many lines as you would like, as long as you understand that all the lines that will be copied or deleted will be below your cursor.

So all the lines below the cursor, including the line where the cursor is, will be affected by this. You do not need a colon and a command line here. You just type the commands dry, basically. So, look, I am in the command mode now. I don’t have the command prompt down there. I have pressed the escape to exit it. All I would need to do now is type in I’m going to go ahead and press two DD. There you go. The two lines have been cut. I’m now going to press P in order to paste them. There you go. They have been pasted, simple as that. I know from time to time this can seem a bit dreary and it can’t prove difficult to motivate yourself to learn BIM or vim.

As you can see, it’s not very user friendly and it has completely different terms. Write, yank, those are things that you wouldn’t usually use well, right. I mean, you would use for partitioning and something of a kind, but you generally wouldn’t use right instead of a term save. However, it is as it is and you absolutely need to learn how to use vim. I mean, on all the server machines, as I stated before, you’re going to find vim and that will be the program installed by default and you will need to know how to use it in order to edit large sets and chunks of files. It is very powerful of that, I assure you, even though it is not user friendly. Anyway, I bet you farewell and I hope to see you in the follow up tutorial.

Comments
* The most recent comment are at the top

Interesting posts

Impact of AI and Machine Learning on IT Certifications: How AI is influencing IT Certification Courses and Exams

The tech world is like a never-ending game of upgrades, and IT certifications are no exception. With Artificial Intelligence (AI) and Machine Learning (ML) taking over everything these days, it’s no surprise they are shaking things up in the world of IT training. As these technologies keep evolving, they are seriously influencing IT certifications, changing… Read More »

Blockchain Technology Certifications: Exploring Certifications For Blockchain Technology And Their Relevance In Various Industries Beyond Just Cryptocurrency

Greetings! So, you’re curious about blockchain technology and wondering if diving into certifications is worth your while? Well, you’ve come to the right place! Blockchain is not just the backbone of cryptocurrency; it’s a revolutionary technology that’s making waves across various industries, from finance to healthcare and beyond. Let’s unpack the world of blockchain certifications… Read More »

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 »

img