EX200 Red Hat Certified System Administrator RHCSA – Linux command line Part 3
7. Commands “grep, pipe, echo, cat.”
All, today we’re just going to continue on with commands. So today I have some, well, some of them perhaps can be referred to as text editing commands, but they are mainly for file listings and for combining with other commands in order to obtain better results. Anyway, I’m going to show you very soon what I mean. So first stuff we have echo. Echo is just read the English word and think to what that particular English word is referring to. Basically an echo. You say something and then it is repeated. Let’s say echo, how are you? Excellent.
So we just echoed it out to the standard output, but this can be also redirected. And I will talk a great deal a bit about redirecting traffic from standard outputs and standard error and such stuff. You do it basically like this with the arrows. Let me just show you a very simplified example of this. So let’s say we want to echo this to a file. Echo, excellent. And now we can use the cat command, which is echo excellent. It says, hey there, how are you? That is the contents of the echo file. But if I change this and if I say just, hey, I’m sorry, hey, it’s going to delete everything in there and it’s just going to write hey.
So be very careful with echo, what you do and how you actually behave with it, primarily because you can end up messing around with the content of other files, deleting them and substituting them with something else. But echo is a very nice thing, especially in bare scripting. It allows you to actually be informed. It allows for that verbose output that you are getting with when you’re running commands, when the program is actually telling you, oh, okay, I am doing this now, after that I’m going to be doing this. It takes me this much time to do that and so on and so forth. So it’s a very nice functionality.
It’s a very nice feature here. Anyway, I’ll just take a look at echo help. Be sure to take a look at oh, wait, no. Okay. This is one of those cases where you cannot access the help like this. But here not we got the man pages. What do the all knowing man pages say? Look, it’s not okay. Yes, it’s a fairly simple command, but that does not have to mean that it doesn’t have any arguments. Just check this out. There’s so much of it, not as much as in the others, but certainly a good amount of them. So you have these escape characters.
We’re going to be learning about them quite a bit later on, but how to use them. But for example, if you wanted to echo a backslash, sorry, if you wanted to, let’s say, echo a quotation mark, you would need to use a backslash as an escape character for that. Or if you wanted to echo a backslash, you would need to use backslash as an escape character for itself. I’ll show you what I mean in a moment, but for the time being, I’m just going to have a look at these options.
Excellent. So we need E to enable interpretation of backslash escapes. Very, very important. I will show you why in a moment. Okay, so capital E is apparently disabled, which is not the best of things. Here you have the synopsis like with any other command. But let me just show you what I mean by this. So if I typed in let’s first clear the screen. If I typed in echo test backslash, what did I get? The command is not done. It’s actually waiting for it’s, offering me a chance to issue more inputs if I type in the quotation marks again. You see what happened there. So first of all, let’s go about this one more time.
Now I have typed in here, echo as before, and I have the quotation marks and I have test, the word test inside. And in addition, at the end of the word test, I have an escape character. Escape character basically tells it, do not interpret this and please print it out, do not interpret it as a part of your command because the quotation marks are part of the command or the argument for the echo. Basically they provide the border lines for the string that you are putting in here. I suppose there isn’t much point to put them now because there’s just one word, but let’s say I have how was your test? How did you do your test? Would be a better way. How did you do your test? Excellent. So now this wouldn’t function without quotation marks because you have spaces in between. If you don’t have any spaces in between the words, then you can do this without the quotation mark or should be able anyway. But since the quotation marks are part of this command, the backslash here tells to the echo that hey, this guy at the end, this last quotation mark is actually not a part of your standard command.
You are supposed to print this out only and not interpret it as a command. You should interpret it as a part of this entire string, which is of course a bit tricky because then echo doesn’t quite understand. It’s just waiting for you to give him more so it can finish. So if I press Enter now, I just get prompted, hey, I need something else. It’s expecting something else. It stands to reason to it that you should type something else. And quite frankly, it is quite rational, as you should. So I just add another quotation mark which will match its twin at the beginning. So these two will be beginning and the end, because this one can’t be as. Actually there is an escape character in front of it and it completely throws it out of the equation. So if I press Enter here, there we go, how did you do your test? And then the quotation mark at the end. That’s pretty much the only way to print quotation marks and some other things, which would generally be considered to be part of the command.
Rather instead, you can use escape characters such as backslash in order to avoid these sort of things. Anyway, that’s why we need escape characters. That is why they’re very useful and that is why we use them. You’re going to use the backslash even though you don’t need it for navigation. Rather instead, you will use it for escaping things such as these. Perhaps not in the echo command, but believe me, there will come a time where you will need to process a lot of things with a lot of other programs, and you will need them anyway. What I showed you a moment ago is in fact this greater than sign. Greater than sign basically says to the echo, okay, whatever you have, redirect your standard output into I don’t know, into some file, some file here, doesn’t matter which one. So just whatever you have, don’t put it to standard output because this is standard output.
When it prints it out to your terminal screen, don’t print it out to the standard output. Rather instead, please redirect it to my file and put it there. So that’s a very nice feature. These things are rather universal escape characters greater than sign. So you are able to in fact, this is not network traffic, but you are able to basically steer the traffic within your machine in a way you want it to function towards a place where you want it to go. And it’s fairly simple. There isn’t that much complication to it. Now, let me just use this echo command in combination with grep command, because that is yet another thing that I wanted to show you. And on top of that, we will need a pipe. Look, this is a pipe. This is a piping sign binder between two commands. It’s basically saying pipe it through. So whatever you have, whatever you output so whatever the echo output and this is the output of the echo, please pass it along. This says the pipe, please pass it along to the command that will stand on this side, and on this side, we will use grep, which basically just pulls something out, grab. And we will say that I don’t know, we want to pull. What shall we pull? I don’t know. Did you just did and if I press enter there you go. It has symbolized. It completely red. Let’s make a file now. Actually, no, we already have a lot of files here that we can I’m sure we can use at least some of them. What do we got in echo? Cat echo. Excellent. So we have hey, but this is not enough. We should do echo. I don’t know. Hey there then, the new line character. How are you? I feel random, amazing, right? No sense of whatsoever. But it doesn’t really matter. You need to get lost and go into the echo. It actually didn’t recognize the new line characters. Okay, no problems. Let’s go and search demand pages for that nibble interpretation of backslash escapes. Oh, I forgot the e.
But it seemed to be able to recognize some of the things backspace produce. Escape form, new line. Okay, so I am correct in using this, but there is one thing that I am missing here, which is lowercase e. Okay, I need a space here. There you go. So cat echo. There you go. So clear the screen. Cat echo. And if you’re wondering what these two spaces are, they were in the original echo. You can see them here. So if I was to delete it here, delete a space here, and delete a space here, press enter and cath echo. No. Why do you have those tabs there? Come on, my good man, come on. What is the deal? I got no idea. It doesn’t really matter for the time being. Maybe I’m doing something wrong with the echo command, but that’s besides the point. What I wanted to show you is the file itself. So you have this weird looking file with those two spaces in the front.
And since you have the file now, imagine that this file was like 400 pages long, and you need to find particular words or particular patterns or, I don’t know, you need to find whatever. How do you do that? Well, okay, sure, a lot of text editors will have a find option, and granted, the terminal text editors also have find options. But if you’re doing something in your terminal and if you just want to figure out what a certain variable value is, or if you want to format it in a way you can pull the text out, you can output the text, the standard output, and then you can redirect it to then you can pass it on to grab actually. And with Grep, you can take particular lines, which you can then in turn pass yet another program to do something with them. Now, okay, you might think that this is a far fetched scenario, but no, this is actually quite common. So, for example, imagine that you have a program which is scanning for thousands of IP addresses, and that program is gathering information whether the port 80 is open or not. It’s looking for web servers.
Anyway, that information, you get a lot of information there. I mean, if you’re using one of well known tools like Nmap, you’re going to get a lot of information aside from the port. You might get, I don’t know, some verbose output, how it was done, what is the geo IP location of that particular IP address? Like, where in the world is it located, and so on and so forth. And let’s say you just need a collection of IP addresses which are in the following format. So you have the IP address. You have a confirmation that the port 80 is open, but you don’t want to put it in the table. You’re just saying, okay, I want the IP address, and I want the city in which this IP address is. You would have to use grepable output, and then you would need to pass it along to something else, like into a file or something of a kind so that food gets sorted in such a fashion later on.
As we progress, Grep will be inevitable. You will see a lot of examples as we use it because we will simply need it. It’s one of the most used commands out there. Anyway, so now that we have this file echo, I just want to show you how can you use graph in order to actually pull lines from it? So here’s what graph does. It matches the pattern, it finds it, and if it finds it in a certain line, it will print that entire line out. So it won’t just print the word out, it will print the entire line, and it will change the color of that particular pattern which was found in that particular line so that you know that it’s there. Anyway, let’s go ahead and say cat echo. And there are countless ways of doing this. I’m just used to doing it like this. But I’m sure that somebody out there knows a simpler way, grab. By simpler, I mean typing less. However, I found this to be a relatively easy and a simple example to follow through to build your foundation. Anyway, cat echo pipe. So pass whatever you plan to put in standard output, don’t pass it to grab. And then grab will actually pull something out of here. Let’s say I want Grep to pull. I don’t know. Hey, pull. Hey. Excellent. So, you see, it has printed out the line, hey there. But grab is case sensitive, and you can type in I to ignore the case.
You see, that’s pretty much the same. And look, it will still print out hay there. Let’s see. EAL. Excellent. You see, it has matched a pattern, and it has printed that line out. So let’s see if I have some common patterns that are the same for at least two lines. Okay, so Gret e how this will actually print out all three of them. Let’s see. With the h. Excellent. With H, it will print out only two of the lines. So, you see, you can pass all sorts of patterns here without any sort of problems of whatsoever, and it will go for it and look for them. Now, as I said, we will use Grep extensively throughout this tutorial, and you will see a great deal more of Grep.
That is why I would strongly recommend that you read the man pages on Grep as extra reading material. You might think that it’s vain or silly or something of a kind. But the creators of these programs have written these manual pages and if you ask any Linux user out there, any Linux system administrator, they will tell you that they wouldn’t be able to function without the man pages or the help or the help in general that you get from the terminal, from the system. So don’t shy away from them, use them. And especially for Grep, I would advise that you do read through it. As you see, you have multiple versions of it. Actually these are completely different programs performing the same purpose as they are a bit more advanced. So you have Grep EGRP f grep egrep is generally used today a lot as well, but for simpler tasks you can use Grep. For something extremely complex you can use egrep as well. Anyway, I bid you farewell here and I hope to see you in the next tutorial.
8. Yum packet manager part 1.
Welcome everybody to this tutorial. Today I will introduce you to the packet manager, the default packet manager of Red Hat. Now, this is the exact same packet manager that sent us uses so don’t worry about it. The commands are the same anyway. The packet manager which Red Hat uses that you can use by a command line. There is one one for graphical user interface but I am going to probably skip that one during the course of this tutorial as the priority is on the terminal and the Red Hat certification will primarily focus on the Terminal and will require you to be able to do this via the command line. Anyway, the command that you use to install and search for any package from the repositories is Yum. So Yum is the default packet manager used for this purpose. Now, before I get into all the technical details and explain what Yum does and how it works and what sort of arguments and parameters can you pass to it and how you can actually install stuff on Linux, let me just go ahead and first say that let me just go ahead and first explain what a packet manager is.
So a packet manager in pretty much any Linux distribution is basically a piece of software, a piece of code which enables you to pull from a remote location, namely from the repositories any piece of code that is within those repositories. And usually like 90% of the cases you have pretty much everything that you need within the repository. So you needn’t actually go on the net and search and download software from unsecured sources. This is one of the main reasons why Linux is superior to any other operating system primarily because you can actually pull from the maintained repositories where maintainers actually where people actually work on those repositories and make sure that all of their content is safe and secure so that you don’t end up downloading a Trojan or a virus or something of a kind. And I do believe that I have mentioned this in some of my previous tutorials this has been running since the 90s or something of a kind. Only recently have Windows and Mac introduced their own methods of this their own packet managers where you can actually go on the net and actually pick things not on the net, sorry, where you can actually go hook up to a place, to a store of a sort and pick things up. But unlike Windows and Mac where you actually have to pay for these things. Okay, granted some things are free, but most aren’t. Using the repositories in Linux you will find that everything is free. All the software from the default repositories is free of charge. As far as I know, I have never encountered anything that I needed to pay for and I have been using Linux now for a very long line, for a long line of years, which is fantastic.
So once again the packet manager enables you to install any piece of software that is within repositories which are listed in your system. It is also possible to add new repositories to your system without bigger difficulty. You just have to edit the file. But please be aware that adding any new repositories you are basically authorizing that repository to forward you the content. So whatever you install, if you install it from that repository that you know little or nothing about, basically can be anything. That is why I would strongly advise to use only official repositories and not to actually add anything. Perhaps you can add on your desktop machines Rpm Fusion, which is very nice for some additional packets for multimedia and stuff of a kind but generally you do not do this, you just use the official repositories and from there you perform the installation. Now, of course, like with any other operating system, you are actually able to go onto the net, download a software for Red Hat or for CentOS and install it. No problems, as long as it is compatible with Linux. And to be more precise, as long as it is compatible with Red Hat distribution of Linux. Because Centaus is, of course, based on Red Hat, fedorai is based on Red Hat, Red Hat is Red Hat. And you also have like Debian, which is basically Ubuntu is based on Debian, mint is based on Debian, and so on and so forth. And you will see that there are two different extensions so Rpm and Deb. Pretty much the packets that concern you are Rpm.
There you go. There are softwares out there which do the conversion from deb to Rpm and vice versa. However, there is no guarantee that it will work, so it is not generally recommended. Rather, instead find the original or the substitute program which has been ported or has an Rpm extension or something of a kind. Anyway, there are other methods of installing software, of course. They don’t need to necessarily be Rpm packages. It can be any code. That you can compile and run that is compatible with Red Hat, although that is not recommended due to security reasons. The best way the most secure way is to download software or software that you need from the official. Repositories of Linux, or should I say from the official repositories of Red Hat where you can find safe and secure software and you can download it with great ease. And you can search through those repositories with great ease. Now, that being said, let me just go ahead and delete this. And now I’m going to use Yum to perform a search so I can type in well, before I actually use it for search, let’s just go over. To help menu. Okay. Immediately. It’s starting. It’s loading up. So this one has quite a comprehensive amount of commands that you can pass to it. And we will be using Yum throughout this course, as we will need to install additional software as well. But this is one of the most important software that you can think of.
This is one of the most important functionalities of your system. The ability to install other software onto it from a remote source at a relatively fast pace, at a relatively good speed. That depends really, on your bandwidth and your processing power. But I haven’t really encountered any problems with it ever. People use it, it’s one of the best things ever invented. Anyway, I once again would strongly recommend that you go ahead and read through these things here in the help menu. You don’t have to go through the entire list of the band pages, but I would definitely advise you to familiarize yourself with the arguments here. Now of course, as with all the other commands, we will not be using every single argument that is here. Rather instead we will be using the ones that are most used, that are of greatest help and use to you, and the ones that you will absolutely need. If you wish to learn more about them, or if you have a question about a particular argument or something of a kind, or a particular section of a command in demand pages or something of a kind, please do not hesitate to pose any questions in the discussions on Udemy. I will be more than happy to answer them.
It is with no small amount of personal satisfaction that I performed this task, as it does bring me. It satisfies me to actually be able to solve problems, to help people out and to basically spread the knowledge, so to say. Anyway, the argument that you will use is verbose as before Y, because sometimes during the installation process you are prompted with questions and well, most of the time you’re prompted with questions actually, but most of the time those questions are standardized. Like you issue the command to install a particular software and then Yum begins the process, it updates the repositories, it finds whatever it is that you are looking for, and then it begins the installation procedure. But before it begins the installation procedure, upon finding what you have wanted it to install, it actually gives you the package. I do believe that it gives you the dependencies as well. And then it asks you do you want this to be installed? It will take this much space on your hard drive, so please verify. And for example, in addition you can have one liners. Those are the commands that do a great deal of things, just one line and you can add Y argument to your Yum installation command and it will answer all questions in advance with yes for you, which can be a useful thing in a vast amount of cases. Anyway, next time is not next time, sorry. The next thing that we are going to do is well, if you have some errors, this is generally not recommended you can say T D for tolerant.
This can cause so many problems. I definitely wouldn’t recommend using this until you become an expert. So to say, quiet operation is basically the opposite of verbose, so that can be very nice if you don’t really care. So just send it to quiet or if you have installed the software, a lot of times the same software. And if you don’t want to check the installation procedure out for the 100 time, feel free to pass the Dash Q. Now, these things tend to happen, skip Broken. Sometimes a package won’t install because it has deemed that some packages are broken, or some libraries or something of a kind. Yeah, you can skip them. And I don’t know about you, but I have done this many times and this thing actually tends to work.
I don’t know, it reports an error somewhere, something is wrong, these things happen and then you can actually say, okay, well you know what, I want you to skip broken for now and let’s see if it’s going to work. Sometimes it’s going to work, sometimes it won’t. That’s the way the cookie crumbles. So to say, you can also say download only, do not update, just download. Which is, I don’t know, I suppose I don’t really see a reason why you would do this unless you were in a real, unless you were in a rush or something of a kind, but it has its uses, although it is not recommended. Anyway, do we have anything else here that I wanted to talk about or that I wanted to include here? I do not believe so. Okay, there we go. I knew I was missing something. So, list of Commands these are the list of commands that you can pass to Yum. So not arguments, but rather instead commands can pass to Yum that will, what will actually Yum do? And then you also pass the arguments to say how will Yum behave while performing a certain operation? Anyway, you got clean, which is very nice. It removes any cached data that cache data sometimes can compose problems, so you can just remove it. Depth list, you can list package dependencies. So I don’t know if you have a package somewhere and you want to install it, and you have some problems with it after installation or during installation or something of a kind. So you can just say, okay, give me a list of dependencies and then you can use locate to find them. If you have them, great, then it’s something else.
If you don’t have them, well, even better, just go ahead and install them and you have solved yourself a problem. Now, Linux possesses the ability to update and downgrade to upgrade and downgrade individual packages. So you can actually downgrade individual packages this year. And believe it or not, people actually use this primarily because perhaps certain things don’t work with the newer versions. Or I mis expressed myself there. Some things from the newer versions of software do not play well with some other software that you have there. So I don’t know, somewhere in the forum somebody suggests that you should downgrade it or something of a kind that’s a reported bug and you then downgrade it. Although it can be a security risk. If it’s not a network application or something of a kind, perhaps it’s worth a while. For example, I couldn’t connect to a router due to my SSH protocol not being compatible with it because the one on the router was ancient.
So I just downgraded the package and I managed to connect even though it was less secure. Okay. It was a local network and the job needed to get done. So we just formed a direct connection with the cable and there you go, no problems. That’s also one of the solution. That’s just an example of one problem there. I know somebody’s going to say, well, you could have used the console port or something of a kind, but didn’t have the cable at the time and needed a quick solution. So a downgrade of the SSH was one of those solutions. By the way, SSH is basically a way of connecting remotely to somewhere that has an equivalent support of the SSH protocol where all traffic between the two of you, between the two points is encrypted, which is very nice because anybody else listening on the desk will not be able to figure out what you are talking about.
Anyway, let’s just go ahead and go down a little bit. So this is one of the most important commands that you will be able to pass to Yum. It is install. This is the one that you will use quite frequently. You will use it to install packages. Well, you can either install one or more. You can tell Yum to practically install an infinite amount of packages at a time and it’s just going to go one by one by one by one and it’s going to install them. And Yum is great because it gives you so much information about the package that you are installing. It’s not just a progression bar or God forbid, it’s not the circle in the Windows. That’s just awful. I know that people okay, in the sense of design, the circle in windows can be great, but it doesn’t really tell you anything. It might as well be bugged. It doesn’t tell you the estimated time completion, doesn’t really tell you what it is doing in the background or anything like that.
But shortly you will see how Yum pretty much tells you every single little thing that it does in the background. So you are aware, okay, granted, for an average user it’s not really important, but for you as a system administrator, it is of extreme importance to know what is going on in the background as is appropriate for you. So it helps you troubleshoot problems. It helps you learn more, it helps you figure out what is going on and therefore you have greater power over the system. The more you know, the more power you have, so to say. You also have info, it displays details about a package or a group of packages. So you can learn a bit more through Yum about a package from the repositories, which is very nice to see if it actually suits your purpose. Now List actually lists a package or a group of packages, which is very nice, practically equivalent to search, but List does everything, so perhaps not the best of things. I generally don’t use list. I use search. It should be here somewhere. There we go, search package details for the given string. And now you see, this is the difference in List. Down here in the search you can actually just pass any string that you want and if Yum actually manages to find any matches in the repositories, it’s going to print those things out to you. It doesn’t matter whether that match is in the package name or in the description of the package or something like that, if it finds that in the line, it’s going to print it out to you.
So you will be able to see all packages containing such strings. A very nice thing indeed. So you can also run interactive yam shells, but for the time being that is beyond our capabilities. Down here you have the update, very important. And below you have upgrades. It upgrades packages taking obsolete into account, very nice as well you can display a version and down we go into arguments. Anyway, these are some of the simplest things. And also, I’m so sorry, I have forgotten this, it’s repo List. It shows you a list of repositories. So let’s just try that one first.
Let’s go ahead and clear the screen. Type in Yum space repo List and you will notice that sometimes, I know it seems like it’s stuck here, but it’s not, it’s actually working on something. So let’s go ahead and deny it that privilege. And type in here space C. There you go. The C will prevent it from running auto updates or anything of a kind. It will basically say just give me what I need, don’t do anything else. That’s the simplest of explanations I can give to you. So there is the repo ID which is basically here and we got the repo name which is here, status repo list and so on and so forth. So here you can actually see which repos do you have on your computer. Aside from this, you can manually perform these checkups as well. And all of this we will like the installation, the search, the manual checkups of the repositories. We will do all of this in the followup tutorials. I will cut the tutorial here and I sincerely hope to see you in my next video.
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 »