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

  • By
  • January 18, 2023
0 Comment

1. Globbing ( wildcards ) part 1. Getting files fast without the entire name.

Welcome back, everybody. We’ll just continue, shall we? So thus far we have covered the wild cards, be it the Asterisk, which is a general wild card where you can substitute practically an infinite amount of characters and any character. Or you could have used a question mark which would substitute only one character with any character. Now we’re going to go ahead to something more specific or something more precise where you will be able to say, okay, well, I wanted to contain these characters, or I wanted to begin with these characters, end with these characters, or not contain these characters or even contain this particular range, which can also be a very nice feature. Anyway, let’s go ahead and give it a shot and see what happens. So if I type in Ll here, I get a listing of all the files that I have in this folder, as before. But let us say that I wanted to print out all the files that begin with, let’s say, R. So I noticed that I have the files random.

So here random and random with a capital R. These are two completely different things, as I do believe I have mentioned before. The next is extremely case sensitive. Let’s go ahead and type in Ll space open bracket, type in R close bracket and then place an Asterisk so we don’t have to type in the rest of the name of the file. Press Enter and there you go. You get two files which begin with R. But notice how we didn’t actually get the file that started with a capital R. Now, if we want to include that file, we would just type the capital R here. So we are telling the first field of the file name will either contain a lowercase R or uppercase R. This is not the second field. You cannot think of it as two fields. So the lowercase R and uppercase R are the same field. So this is basically equivalent to this. Either the first field of the file name will contain our lowercase or our upper case. These are not two separate positions. Probably a better thing to say that there are positions as opposed to fields. Anyway, so these are not two separate positions. This is one exact position.

Except you’re telling the machine it either begins with lowercase R or it begins with uppercase R and then we are going to get it. Surely enough. You see that indeed we got three files printed out anyway. You can put this pretty much anywhere you want depending on the purpose at hand. Depending on the task at hand, you can substitute any position in the file name. So let me just give you an example of this. Now, we are going to define the second position. Only when you open close the brackets. Again, are you actually defining the second position, or the third, 4th or last and second to last. Because this could just as easily have been written out like this. And how do we want this file to end? Let’s say we want it to end with E. Excellent. So we are effectively telling the machine all files that end with letter E should be printed out, the standard output and surely enough we get them here, no problems. But what I wanted to show you is defining other fields.

So if I type in open bracket and I say D, second field shall be O, then we’re going to put an Asterisk here and then asterisk here and press Enter. Well, a poor example here because they all pretty much contain do except for the last one. But doesn’t matter, I think you get the idea here. It can be preceded by anything and it can end with anything. It contains a D character somewhere in the middle, followed by an O character. And surely enough, all of these files, they do contain do somewhere within their name, except for the last one, which you can see that it was not printed out. So the command was successful anyway. I could have also said Dom. So we’re going to get pretty much the same output. But I just want to show you that you can specify multiple characters. You can specify multiple positions, no problems. You could also have specified different characters at these multiple positions. So this one would have UiO and this one would have Pol. This would be a huge amount of well, maybe not a huge amount of combinations, but certainly a significant amount. Basically what we said it can contain D-E-G-S-F shouldn’t price twice. And then it will be followed by either by UI or O. And then it will be followed by PO, L or N. We would be casting a pretty wide net with this, but it doesn’t really matter. What I want to do here is demonstrate that you can specify multiple positions.

Now, you can also say clear, you can also say that you want to exclude certain characters if I type in Ll and if I say if I type in the question mark, the question mark is pretty much the universal negation either in programming or here in Linux and Linux Terminal. I can say, let’s say that Is is excluded as the beginning of the file. And you will see all the files that began with Is are no longer here. They can no longer be here as they are excluded. Just an exclamation mark means does not contain and we are negating these two characters, therefore excluding them from our output. There is just one more thing that I wish to mention here and those are the ranges. So for that purpose, for that purpose I’ve actually created these files. Is random.

Zero, zero, zero one, zero two, zero three, zero four and five. Let’s go ahead and see how that breaks out. Type in Ll, give it a wild card. Or we can type in Is random because we’ve used the wild card before. I just want to show you that this does work without full wild card. You can combine it also with words, letters that you know from the file name and I’m going to say underline. So for the second to last character, which is we can see the second to last are these characters here. I can see that they’re all zeros. So no need to give it a range. I can just type in zero next to that. I can open up a bracket and say okay, now I would like to have a range here.

The range shall be from zero to five closer bracket and surely enough only those files get printed out without any difficulties of whatsoever. Now this should work like this as well. There we go. So they all get printed out once again without any problems whatsoever. I have left the underline there, not sure exactly why, maybe just missed it, didn’t see it, but doesn’t really matter even if this underline wasn’t here. As I said, Asterisk stands for any character. Absolutely. So no problems there anyway. You can inject these ranges pretty much anywhere you want within your file and place text in front and behind or even in between. And then you can also give it wild cards and stuff like that. I strongly recommend that you experiment with this as much as you can as these are some of the things which will be used to rather large.

These are the sort of things, these tricks so to say, that are used by network administrators all the time to generate scripts which automate tasks primarily because you won’t always know the names of the files and you will need to use them. Of course you can use Locator find, but to actually run Locator find every time to search through the whole system for the sake of file names is resource expensive and you don’t really want to do that. Instead, when you need to, for example, grab a file name, put it into a script, a bash script and then do something with that file and basket usually edit it, change it in some way, change some values in it. Then you would use things like these to pull the file names out of a let’s say out of a configuration, out of Etsy or out of log directory. And then you would do it, for example logs if you’re logging some sort of activity, if you want to see what is going on and you’ve enabled logging, we will deal with this subject more extensively later.

What you say is that okay, this log gets created now for the activity of the file. And then, after a certain amount of time has elapsed, I want you to stop writing to that particular file, create a new one, and continue writing the logs so that your individual log files are not too big and you can manipulate them with greater ease and they are segmented. So you can delete certain parts of it more easily and so on and so forth. But the naming of those files is basically by index. So you say that you tell the basket to name the files like 0001 and so on and so forth. Usually would place a date here so you know when it is actually done. If this is not sitting too well with you now, don’t worry. I don’t want you to worry about it if we will deal with these sort of subjects later on. I’m just giving you an example here of what this particular thing that we have just done is used for.

You would want to say, I don’t know, list me all the log files that contain a particular month or a year or something of a kind. So we just put in like a wild card. And then in the ranges in this range you would be able to type in the date pretty much. You would give it a range here in the first one and then you would give it a second range. Well, actually we just use two. You would type in the range for the month. Which month do you want to be included? I don’t know. You obviously wouldn’t be able to type in zero for a month. Rather instead you would say from 6th to 8th month in the year 2014. 2015. Now, but I’m just using a reference. So all the files which contain these sets of numbers shall be printed out basically the month and the year. You want to print all the log files that were made in between the 6th month and the 8th month. That’s one way to configure logging. There are of course others, but usually they configure them by date. And this would be one of the methods. Roughly, this is not the correct syntax because you would actually see the file name.

To figure out the correct syntax, you would probably need to put something in between here, like minus sign or something of a kind. And then this would make far more sense. But I wouldn’t just put a minus sign. I would go about things like this and this would be very nice. Obviously, if I press Enter LS cannot access no such file directory. There is nothing under such name in my desktop folder. But doesn’t really matter. That’s not what I wanted to do today. This is just an example that I wanted to give to you so that you would understand this with greater clarity. So you see what I’ve done here. If I am in the folder where the logs are made, I can tell it all the log files that were made in between 6th and eight months, 6th and 8th included. Now this is just the syntax.

Usually you would have a minus separating the month from a year. And then you can specify, okay, these months for this particular year. Then please pull the output. And you would usually put something like this, like grep and there would be a particular line or something of a kind that you would want to pull out. So you would give a matching expression here which would be like login so there could be a line login and you would pull everything that’s contained you would pull all the lines that contained word login in between on these particular dates.

Anyway, as I said, if this last part is not sitting too well with you it’s perfectly fine, it’s perfectly natural and just like introducing new subjects at random and when we actually get to them you will be at least familiar to a certain extent. But what is important for you to understand today in this particular tutorial is the idea of globing. So I’ve had two tutorials thus far on globing. We’ve done the wild cards, we’ve done single character wild cards, we’ve done particular characters negating the particular characters ranges as well. So these five basic ways of these five basic filters I would say I would strongly urge you to know them and learn them and experiment with them primarily because because you will be using them extensively as a Linux administrator. That would be all I would like to be your farewell and a ton load of luck. Until next time.

2. Globbing ( wildcards ) part 2.

Welcome back, everybody. Today I’m going to go ahead and start talking about input output redirection. So we have three basic concepts here. We have standard input, standard output, and standard error. What are they? Standard input? Well, that would be something that you would type in that you would use your keyboard to actually input, let’s say type in who am I? For the people who have amnesia, just type in and there you go. I am at the moment root. If I exit Root and type in who am I? Again, I’m going to get random guy. That would be standard input, me typing in something into the terminal or pretty much anywhere else. Standard output would be this return value if we get here, maybe not the return value, but something that gets printed out. It says random guide.

That is the username of the current user. Anyway, standard error is useful. How shall I put this to the point of extreme? Basically, you do something and then your system reports that it can’t do it and it gives you an error message. And that error message 99% of the time you can actually just copy paste onto the Internet. The chances of somebody that somebody else has encountered the error are pretty high and if they have chances that somebody has posted a solution are even higher. Very nice way to troubleshoot things, especially when you get what you need from first try. But usually you have to dig a bit deeper. Anyway, now that you know what standard input output and standard error are, let’s talk a little bit about why do you need them.

I mean, of course this is used on daily operations primarily because you would want the output of one command to be the input of another. So you’re just passing along the arguments. Especially useful for bash scripting in Linux. Bash scripting would be just a list of commands that you would utilize that you would be able to type in individually into the terminal anyway, but you type them in as a bulk and you use them for task automation. Let’s put it so anyway, here’s a blunt example where redirection would be awesome, although not strictly speaking of redirection. I can just type well, I suppose it is. I can type in who am I? And I can redirect it to a file which will be my home directory. So who am I? Press enter and type in cat. Come on, cat. Who am I? There you go.

So we have successfully obtained the username of the system. We have placed it into a file and now we can retrieve it. Okay, so what did we do here? You see this greater than sign it’s redirecting whatever this is outputting from standard output to a file whose path is the home directory of the current user. This is just how you would redirect the standard output, nothing else. So no error messages or anything of a kind. This is just a redirection of what the command would normally output, which is the user name. What would this be useful for? Well, sometimes you cannot actually let’s say you’re providing tech support or something of a kind and I don’t know, a user wants you to do something and you need their username to do it, but you can’t genuinely ask them. Rather instead you’re just giving them the command that they should run on their system so you would be able to do something of a kind. Let’s take a blunt command, let’s type in CD and I would type in Home.

And how would you know the username here? Well, simply enough you would just type in the dollar sign bracket and who am I? Close, press Enter and there we go. We have successfully changed the directory from root to random guy without even knowing the user name. So this is a bit of a general command I would say. However, you can also go ahead and do this now echo who am I? Sorry we can just go ahead and cat this there we go, so random guy and we can pipe it to, I don’t know, to pretty much whatever is needed out there. Like let’s say we cat the who am I? And then we’re going to go ahead and not Cat, but let’s type in who am I? This is what I wanted to actually show you. Let’s say that we now have the username there and instead of who am I? We’re going to type in the command ID. And with ID we get some useful information about the user as well. In addition to just the user name, you get the group, the ID and so on.

What if you want to redirect this output to that same file? Well if you did pretty much the same thing as we did before, we would overwrite the content of that file and it would be gone. So the username would be gone. But this information that we got from ID, from standard output would go into that file. Let me, allow me to demonstrate. So, Cat, who am I? Now in who am I? We have a username random guy and if we do this ID, and if we redirect this to Who Am I? Again. Cat. Who am I? You can see that there isn’t even a trace of what was there before. Now this is not a good thing generally. That’s why we have for the redirection of standard output append function, let’s go ahead and type in one more time and redirected to the file who am I? Excellent. So now we have overwritten the contents of the file once again and this time this time we do not want to overwrite the contents of the file. Rather instead what we would like to do is append it.

So go ahead and type in ID and all that you need to do to append the contents of the file, not to delete it or anything of a kind, or overwrite it. Just type in double greater than sign, so greater than sign redirect standard output, double greater than sign redirect, not redirect, but rather instead sure, redirect, but append. Do not override redirect and append, not redirect and overwrite. Am I? And if we do cat who am I? Now, there you go. You can see that the file has indeed been appended. We have random guy, it is still there, no problems and we have the output from the ID command as well. It stands there without any problems. You won’t be destroying the content. Usually a pretty good idea to use redirect and append as opposed to redirect and overwrite.

Not very nice I would say. Also there is another approach to all of this aside from redirecting error messages to a file or somewhere else or redirecting the standard output of one command to another command as input it’s fascinating to know that you are actually able to basically redirect the outputs to nowhere if you do this. So, Cat, who am I? And if I do this, if I type in dev null, press Enter, this is going to go to nowhere. So gone, no problems, it’s somewhere. Well, obviously it has went somewhere but if you redirect it todevnull it’s pretty much the equivalent of redirecting the output to nowhere. You might wonder yourself why do we want this? Why would you redirect the output to nowhere? Well, I’m going to show you some examples in the follow up tutorial but for the time being, just imagine that you are getting like 40 error messages from a command and only one message from standard output so you would like just to see that message from standard output or it could be vice versa. You could be getting a lot of standard output and just a few error messages.

So you would want to be able to remove some of those things. And then you would either redirect standard output or standard error to null because you don’t want it at that point of time. And you would only be able to see a certain type of messages. I will demonstrate this with example, with plenty of examples in the follow up tutorial. For the time being I just wanted to introduce you to the concepts of redirection as this is one of those subjects that is quite important and it is one of those basic subjects but frequent but what you learn with it what you learned in this tutorial, trust me, you will use throughout your career as a network, as a system administrator, or as a regular or even as a regular Linux user. Anyway, I bid you all farewell until next tutorial.

3. I/O Redirection part 1. Input and output redirection with standard input/output.

Hello everybody and welcome to this tutorial. Today I’m going to go ahead and continue talking about input output redirections. I have here a small text for you. So basically if you want to redirect the standard error, you can do this. But what I want to show you here is that you can redirect standard error, type in an m percent sign in between and then one, and this would redirect the standard error to standard output. Another one. There’s another line at the bottom which is basically a combination of the two and then a third which is a pipe. The point of this, what I’m telling you now is that you can actually combine these redirections so you can combine them in one single line and use them as filters as well. Let me just show you what I mean by that. I’m just going to expand this one here and for the purposes of this tutorial I’m going to take the output of the PS command which will list the running processes. That’s not what I wanted. Help me out here.

Psef. Excellent. So this will give us a list of running processes on the system. There’s also another neat command which you can type in. I’m not sure if the program is installed. It is. It’s actually top. So you type in Top and it gives you an active display of running processes. You can press Shift and page up and down. It’s a virtual machine so it won’t work here, but you just press the errors to actually list them up and down. I think I can press Shift page up and down as well, but not here anyway, you just keep pressing up and down errors which is actually a lot simpler. And you have a list of link processes as they are happening. This is basically a live feed. You also have the CPU usage and stuff of a kind but we will deal with these tools more later on. For the time being we’re just going to go ahead and use PS and EF PSE with arguments EF which is going to give us a list of all processes regardless of the user as well. Anyway, you type in space but this is like a passive one as opposed to that one up there as opposed to Top because Top is alive. And this only gives you a list of running processes at the time of the commands execution.

Anyway, let’s go ahead and press Enter here and see what we get. So we got Root, which is the username. We got this number which is the PID and this is what we are interested in. This is the process Identifier and then you have the files here on the far right side. Anyway, I have a process running, it’s called Firefox, which is my browser here. And if I wanted to close that browser I would just type in Kill and well, this is not a good overview of things we’ll just clear the screen and do this BS pipe the redirection that we were just doing. Grab it. Let’s utilize it. Firefox, press Enter and there you go. It’s actually very nice. What? No, come on, I need another one. Where is it? Why are you not listing it out? Interesting. I misspelled it. Firefox. Excellent. So over here we have the Process, which is grabbed. This is going to die the moment you press Enter because the command has already executed. And this year is our running process, which is Firefox.

You can see where it is located, and in such a way, you can figure out is that the right thing to kill or not? Is that what you want to kill? If I just zoom it out a little bit, I want you to see that it’s actually going to die, quite literally. The process. ID is seven 3347-334-7334. There we go. We have effectively killed it if we do grep. Firefox. Again, you can only see that there is Grab in the Process list, nothing else. Anyway, let’s go ahead and type in PSPACE EF and let’s grab the Process ID. For the Process ID, I am going to use the AUC command, which allows me to filter things through, which allows me to filter separate fields on the same line, and it allows me to actually define what the field delimiter will be. Okay, I know it sounds a bit I wouldn’t say complicated, but a bit strange. But look, this is one line that I am selecting it now. And in this line I have things such as root, I have spaces, I have some numbers. And let’s say that from this line, the only thing that I would like to pull is this particular number.

Nothing else, nothing more. Or that I would like to pull these sets of numbers or this line, or this part of the line here. How would we do that? What would be necessary? Well, we would first need to separate this line into fields and then specify which fields that we want to print out. But what shall we use as a field delimiter here? What is universal and what fits our purpose? Well, in this particular case, space is nice, so we can use space as a field limiter between these fields, and then we can say that the field one is root and the field two is the number, this number, which is PID. And then the field three is this number. Field four, this one, field five, this one, and so on and so forth. Now, you could have just easily had a semicolon here or a minus sign or something of a kind, and you could have used them as field delimiters. But hold on, let me just show you a practical example of this.

I’m sure you’ll be able to figure it out. Let’s use Psef and then use AUC space, capital F, which will stand for our field delimiter here. When you type in a minus sign, capital F, after that, you can specify your field elementors, field diameters. It can be pretty much any characters or pretty much anything that you can specify that is acceptable, I suppose, here. In this particular case, I’m going to use space. So how do we define space? We just type in quotation mark. Space. Quotation mark, and that is space. When I type in the quotation marks, I don’t need them here, but I’m just going to type them anywhere because of my habits. Print, basically, you’re telling it to print something out and then dollar sign. We can do it with dollar sign, second field, close the curly brackets and close the quotation marks. Look at this.

I have managed to print out every single number, every single number from that particular field, which is very nice. These numbers are already sorted by size here, so we don’t need to do any sorting there. But look, this is still being printed to standard output. Now we can redirect the standard output of this command to Rev. Rev is basically used for reversing. It’s going to reverse the order of these numbers in each one of these slides. So it’s no longer be ten, six, four, three. It’s going to be 34601. Okay, now, so let’s go ahead and actually pass the output of this command into rev. How should we do this? We will add yet another pipe and we will simply type in Rev. Rev is a reverse short of reverse, really. So what we do with rev, we reverse the order of these numbers. We reverse the order of numbers of each single line. So we have 1064 three. This will become 34 61.

Let me just show you what I mean by that. Press Enter and there we go. 34 61. Fairly simple enough. We can add this to a file NUMS. Press Enter, and we can also do the following. And then cat numbs. Press Enter and there you go. It’s 34 61. Now we can go ahead and do this again. We can reverse it one more time. There we go. We’ve successfully reversed it twice during 34 61 and then coming back again, 1064 three. But we do not necessarily need to actually do this. We can also type in rev, and now we can have a double output, I think, if I’m not mistaken. Let’s just go ahead, let’s verify this by just repeating actually, we don’t need to repeat the command. We can just okay, and let’s just add another line here, which will basically be, again, end and end, cat numbs.

So we have 1060. I’ve actually appended it twice, but it doesn’t really matter. It’s like 123-45-6789 and it’s zero one. You see, this is reversed. Let’s go down, down. We must go further into the depths of these numbers. And there we go. It’s 123-45-6789 and then it’s 10. So it means it’s ten. It’s no longer zero one, which is again extremely nice. So we just combined the two into one file. There we go. This was an example of a bit of a longer command we will deal further with this and I still need to some things with errors and primarily with errors and how you can actually mess around with those things and the log files but that we shall do a bit later on. For the time being, I just want to show you that you can do these multiple redirects just one after another, no problems. However, we are yet to do the combinations that I have showed you at the very beginning of this tutorial. Don’t worry about I just want to tell you that you shouldn’t worry that much about AWK because we will be doing that further on. Rev, you can go ahead and memorize here if you would like. It’s a very neat command to know. It can help you a great deal. One really simple example of rev being useful to the point of extreme and I can actually show you this in the follow up tutorial is when you want to remove, let’s say, the last two numbers or something of a kind and the length of these numbers is not the same.

So you see you have 4714 here and then you have 1064 three so you would be able to specify okay, remove numbers at position at position I don’t know, 12345 at position five and four and this would be an invalid statement for this upper number here. What you could say instead is okay, reverse the numbers, let these two positions be the first and then you can just say okay, remove positions one and two which is practical to the point which is infinitely practical as you can just reverse them back and there you go. You have indeed successfully removed the two last digits from pretty much any number from bottom to top.

I’ll show you this in the followup example and I will also deal with error messages and we’ll see if we can get and see if I can get into log files and do something of a kind there with redirects as that is one of the priority concerns of all network administrators to deal with log files, to read through them and to process them but we will deal with log files in more detail. However, in the next tutorial I just wanted to actually give you a few more examples in this regard as this is quite an important subject for you to master. It’s not that complicated, it can be intimidating a little bit but believe me, it is one of the most important things that you will learn while using Linux and that is these sort of things, these redirections and text file processing anyway, I bid you all farewell and I hope to see you in the followup tutorial.

Comments
* The most recent comment are at the top

Interesting posts

The Growing Demand for IT Certifications in the Fintech Industry

The fintech industry is experiencing an unprecedented boom, driven by the relentless pace of technological innovation and the increasing integration of financial services with digital platforms. As the lines between finance and technology blur, the need for highly skilled professionals who can navigate both worlds is greater than ever. One of the most effective ways… Read More »

CompTIA Security+ vs. CEH: Entry-Level Cybersecurity Certifications Compared

In today’s digital world, cybersecurity is no longer just a technical concern; it’s a critical business priority. With cyber threats evolving rapidly, organizations of all sizes are seeking skilled professionals to protect their digital assets. For those looking to break into the cybersecurity field, earning a certification is a great way to validate your skills… Read More »

The Evolving Role of ITIL: What’s New in ITIL 4 Managing Professional Transition Exam?

If you’ve been in the IT service management (ITSM) world for a while, you’ve probably heard of ITIL – the framework that’s been guiding IT professionals in delivering high-quality services for decades. The Information Technology Infrastructure Library (ITIL) has evolved significantly over the years, and its latest iteration, ITIL 4, marks a substantial shift in… Read More »

SASE and Zero Trust: How New Security Architectures are Shaping Cisco’s CyberOps Certification

As cybersecurity threats become increasingly sophisticated and pervasive, traditional security models are proving inadequate for today’s complex digital environments. To address these challenges, modern security frameworks such as SASE (Secure Access Service Edge) and Zero Trust are revolutionizing how organizations protect their networks and data. Recognizing the shift towards these advanced security architectures, Cisco has… Read More »

CompTIA’s CASP+ (CAS-004) Gets Tougher: What’s New in Advanced Security Practitioner Certification?

The cybersecurity landscape is constantly evolving, and with it, the certifications that validate the expertise of security professionals must adapt to address new challenges and technologies. CompTIA’s CASP+ (CompTIA Advanced Security Practitioner) certification has long been a hallmark of advanced knowledge in cybersecurity, distinguishing those who are capable of designing, implementing, and managing enterprise-level security… Read More »

Azure DevOps Engineer Expert Certification: What’s Changed in the New AZ-400 Exam Blueprint?

The cloud landscape is evolving at a breakneck pace, and with it, the certifications that validate an IT professional’s skills. One such certification is the Microsoft Certified: DevOps Engineer Expert, which is validated through the AZ-400 exam. This exam has undergone significant changes to reflect the latest trends, tools, and methodologies in the DevOps world.… Read More »

img