What you'll learn
- Navigate the Linux directory structure using pwd, ls, and cd to locate and move between folders
- Create nested directories with mkdir -p, create files with touch, and remove empty directories with rmdir
- Redirect echo output from standard output into a file and edit file contents with the nano text editor
- Search file contents with grep, including case-insensitive matching for a specific word
- Use sed to print specific lines and substitute text so the change is written to the file itself
- Set up an Ubuntu virtual machine lab with snapshots so configuration mistakes can be rolled back safely
Free 57-minute video lesson with a full transcript and knowledge checks. No account needed to watch.
Introduction to AutoOps+
In this video we discuss what we can expect from the AutoOps+ examination. We briefly talk about the core skills tested and walk through the creation of our lab environment. Check it out!
Knowledge Check
The course recommends setting up a home lab environment using Ubuntu installed on a virtual machine
Listing and Changing Directories
Now that we have our lab environment up and running, let's get to the fun stuff! In this video we begin learning the commands on the Linux command line interface (CLI) to change directories and list their contents.
Knowledge Check
Which command is used to print the current working directory in a Linux command line interface?
Exploring Other Commands
Let's now explore some more common Linux commands! In this video we discuss how to perform the following tasks:
- Creating directories
- Deleting directories
- Creating files
- Copying files
- Moving files
- Echoing text and redirecting outputs
- Reading the content of files
Check it out!
Knowledge Check
Which command allows you to create a directory along with any necessary parent directories in Linux?
Filtering Text with Grep
Now let's turn our attention towards using one of the most powerful and useful commands in the Linux CLI - grep. This particular utility allows us to filter text data in a variety of different ways. Let's have some fun and explore!
Knowledge Check
Which command allows you to search for a pattern in a file while ignoring case sensitivity in Linux?
Sed and Awk
In this video we learn how to use two more popular command line tools - "sed" and "awk". Sed is a stream editor and allows us to manipulate text streams in a powerful and flexible manner. Awk is also a text processing tool, but specialises in managing "structured" data - namely, the type of data you would see in logs or spreadsheets.
Knowledge Check
What does the '-n' option do when used with the 'sed' command in Linux?
Using the Pipe
Finally, the last tool we will explore in this skill is the use of the pipe utility. The pipe allows us to chain together multiple different CLI commands in unique and expressive ways. As such, it is one of the most powerful tools on the Linux CLI. Check it out!
Knowledge Check
What does the pipe symbol '|' do in a Linux command line?
Validation
Let's now validate what we've learned within this skill!
Instructions:
Launch the lab below. Once loaded, double click on the Ubuntu1 shortcut on the desktop. This will open an Ubuntu virtual machine. Next, open up a terminal window and perform the following actions:
- Print the current working directory
- List its contents
- Create a folder called "validation-folder" and change into this directory
- Create a text file inside this directory called "validation.txt"
- Use the nano text editor to edit this file and enter the following text:
Learning Linux is fun!
- Next, save the content and exit the nano editor
- Use grep to search the content of the text file for the presence of the word "linux" - ensure that the search is case insensitive.
- Next use sed to substitute the word "fun" for the word "awesome" - ensure that the content inside the text file itself is modified.
- Finally, navigate to the home directory and delete the "validation-folder" directory - including all of its content.
Check out the video solution below!
Knowledge Check
How much experience do you have with the Linux CLI?
This interactive assessment is available in the full learning experience.
View Transcript
Introduction to AutoOps+
0:00Hey friends and welcome to the AutoOps Plus course here on CBT Nuggets. Alrighty oh so what I want to do in this video is just to kind of tell you about some of the things you can expect within this particular course as well as how you at home can set up your lab environment so that you can more easily follow along with what I'm doing myself on my own system. Now that said what I will say is that this course is going to provide to you a lab environment whereby even if you do not have your own home lab set up you will have access to the labs within CBT Nuggets to practice all the commands and all the configurations that we go through. However I do always recommend you have your own home lab environment because it gives you a little bit more freedom a little bit more flexibility and access to play with things and to really master all the concepts that we're going to be talking about. Okay so with that said John shut up let's talk about what we're going to be learning within this particular course. So we can see here straight away the skills that we're going to be learning as it's outlined via CompTIA as we're going to learn to use scripting and automation that's going to help us streamline our IT workflows manage enterprise systems. Sounds pretty fun we're also going to learn how we can automate configuration provision and maintenance using infrastructure as code and modern
1:19toolchains that we'll talk about what infrastructure as code actually means later on within this course but suffice to say it's a cool concept and it's very very fun to work with. We'll also be doing things like building CI CD pipelines to automate testing ensure that we have quality and improve the collaboration and workflow between our teams and of course like anything we always want to be automating and managing our infrastructure securely so we're going to have a focus on secure pipelines allow you to deploy your configurations in a safe and efficient manner. So by all means I would encourage you to go to the CompTIA website look up the AutoOps Plus course and look at all the exam details and basically if you go to the website you're going to get a lot more detailed information about the things that you can expect within this examination and in fact if you go down to the bottom of the page you will see that we actually have the AutoOps exam objectives now as I record this the exam has not yet been released so this here is just a draft version but perhaps if you're watching this in the future you will see the final objectives actually printed on here so again if we click this what it's going to do is give you a full breakdown about all the technologies and all of the objectives within the examination itself so we can see we have tons and tons and tons of stuff to get to
2:36all of which is going to be a lot of fun now what I will say though is that in this particular skill what we are going to be focused in on are command line utilities okay now the reason why we are actually starting with this is because in my opinion this is the foundation of everything that we're going to be doing so with that said before we begin diving in to the actual hands-on configurations on the command line what I want to do is just to tell you a little bit about this lab environment alrighty oh so what I will say is that with respect to the configurations that we're going to be doing the examples I will be showing you will be built on Ubuntu so Ubuntu is a Linux based environment and quite honestly the commands you're going to be seeing here will be applicable across pretty much all Linux distributions but that said Ubuntu is a nice friendly distribution so I kind of feel there is a very good entry point so what I would do is I would suggest you go and go to the website click on download Ubuntu and what I will say is you can install this directly in a bare metal environment but what I will say is that my strong strong recommendation is that you install this within a virtual machine the reason being is because when you're dealing with these commands when you're dealing with all these new tools you can often make well you can make mistakes and it can basically kind of break your system
3:51and quite honestly that is not going to be fun whereas if we have a virtual environment if you break something it's easy to just roll back into an earlier snapshot and get back to your safe configurations so basically that is my recommendation I suggest you download an Ubuntu machine and quite honestly my real recommendation is to download two of these virtual machines actually because what that means therefore is that we can actually test the communications between two different devices now what I will say is that for the vast majority of this course you're going to have a main machine one of these VMs is going to be the one that you do pretty much all of your configurations on okay so you don't necessarily have to have two but just in the corner cases whereby we want to have a little bit of networking a little bit of communication it's going to make things a little bit easier now that said again I stress if you only just have one machine in the lab environment that I have built for you in this particular course you will have access to two different machines so again as a fallback you can always use those two and those will be two Ubuntu machines just like I'm recommending in this particular video so friends with that said with all that said let's now in the very next video get to the fun stuff and begin using the Linux command line interface
Listing and Changing Directories
0:00All right, so let's get to the fun stuff. So what I have here is my Ubuntu virtual machine. All I'm going to do is take it down to the bottom left of the screen. Click this right here. So it's going to go here and I'm going to search for terminal window, which will give us our little command line box. And all I'm going to do here is to full screen this. All right, so the first thing we want to understand is whereabouts are we in the actual directory structure? And we want to be able to move through that directory structure just like if you're on the graphical user interface. You can, you know, open up a folder like so and you can click into these folders, you know, double click this here and you know, you can select a file or drag and drop files, that type of thing.
0:36We want to be able to do this within the actual command line interface. And again, understanding where we are is very, very important. So the first command I'm going to look at is one known as PWD. This is print the working directory, meaning that show me the directory that I'm in right now. So let's go and see this. Since if I just say PWD and hit enter, this is the directory structure. Now, my little name here is just ipv0. This is the name that I use online for my GitHub, my YouTube, that type of thing. And basically, this is the username that I created on the system.
1:09So what I have here is my home directory. This is the full path home and then the name of the user. So you're at home, you should see the home directory and then your own username. So that shows us whereabouts we are. And if I want to see the contents that are inside of this directory, what I want to do is I want to list the contents. And the way I can do this is by pressing the ls command. Now, if I do this, we're going to see here, these are all the folders that are inside this particular directory structure. So inside my home directory, I've got a desktop folder, documents, downloads, music, so on, so forth.
1:41Now, before I actually go on to the next command, let me show you what we can do here. We can also use a particular switch, meaning that we can ultimately modify the impact of this particular command by just adding in some additional options. Now, before I do this, I just want to go briefly in and just show you this particular page. See if I say man and then specify the actual command that I want to be using, I will look at the manual page for that particular command, okay? So if I say man and then say I want to see the manual page for the ls and hit enter, it's going to go and tell me what this particular tool does.
2:14So it's going to list content directories. And then we see all of these additional options right here. So again, if I just scroll down, for example, and check this out right here, if we do a dash lowercase l, this is going to use a long listing format. So let's press Q to quit, go back to the page. And if I just do ls dash l and to enter, once again, we're going to see the content of the directory, but we're getting a longer listing. We're seeing when the directory structure was created. We're seeing the permissions on the left-hand side. We're seeing the owner and the group to which that directory belongs.
2:48And we're seeing information about the size of the directory as well. Now, if I wanted to move into one of these directories, say, for example, go into, let's say, the documents directory, what I want to do is I want to change directories. And the command for that is going to be cd. So let's say cd and then give the name of the directory. So I can say cd documents. And what you will notice, by the way, is that once I have typed enough letters, I can just hit the tab button, and it's going to go and autocomplete the rest. So if I hit enter here, I've now changed into the documents directory, and I can confirm this with the pwd commands.
3:21If I enter here, we can see I'm actually inside documents, which is inside my home directory. Now, if I want to go back a directory, move back to where I was, I can say cd space dot dot. That is going to allow me to jump back at a level, okay? So if I hit enter and do a pwd, once again, I'm back in my home directory. Now, let me show you something that we can do here. We also have this concept of an absolute path and a relative path. So when we're talking about an absolute path, we're talking about providing the full directory structure, okay? Whereas, if we happen to specify the relative path, we specify the path relative to where we already are in the directory structure.
3:59Now, again, that might sound a little bit odd, so let me go and tell you what I mean. So right now, if I go and do cd documents, and to enter, what I just used was a relative path. I could just shortcut it to say documents because I'm already inside home ipv0. So again, if I go back and I do pwd, what I could also do if I wanted to give the absolute path, I could say move into home ipv0 and documents like so. And again, I'm back in that same directory. And again, I can do cd back back. There we go. Now, it might seem a little bit strange as to why you would ever want to do the long version, you know, specifying all of these additional directories, okay?
4:36But ultimately, it just gives you a little bit of clarity and certainty depending on whereabouts you are. So say, for example, I do cd forward slash. What this does, it takes me to the root of the directory structure. So if I go and do a listing here, this is me at the very root of the tree. Now, inside of here, we have all the folders that exist on the file system itself. So what you'll notice is that my home directory is in, well, it's in the home folder. And inside that, we have a directory for my own username. And we can see here, this directory is right there. It's in home, okay? So in fact, you know what? Let me do a long listing.
5:06So say, for example, I went into, or don't know, let's just maybe say I go into the temp directory, okay? So down here, see this one right here? Let's go inside here. So if I just say forward slash tmp, cd into that, I'm now inside this directory. But now let's say I wanted to go into the documents directory inside my own home. Well, relative to where I am, it may just be easier to specify the full absolute path. Say, for example, let's say I don't care where I am right now. I just want to go to this exact place. So if I do this right here, it doesn't matter where I am.
5:37I could do a pwd, and I'm now back in. Again, let's repeat that process. If I do cd forward slash, and I go back into the temp directory, what I could do now is give the relative path, which would mean I could say cd. I have to go back a directory to get me to the root, and then say forward slash home, forward slash ipv0, forward slash documents. So as you can see in this case, the relative path is actually longer by having to supply these additional characters, okay? That's right here. So let's just go and hit enter, see where we end up.
6:08Again, as we're gonna see here, we're now back in the same position. Now, a little shortcut that you can do if you want to go back to the previous directory you were in, regardless of where it is, if you do cd and then the hyphen, that'll take you back to the previous directory. So that was gonna be in the temp directories. If I hit enter here, we're gonna see here, I'm now back in tmp, like so. Now, another good shortcut you can use to get back to your home directory is just by typing the command cd. So regardless of whereabouts you are, say for example, I do cd back back. So say for example, I go into the user directory and then go further deeper.
6:39I go into lib, do a listing, now go into, I don't know, let's say locale, do a listing. As we can see right here, I'm getting deeper and deeper into this particular directory structure inside the user directory, more and more of the subfolders. Now, as opposed to me having to go cd back back to go into the previous directory and then back back and then back back and then saying home ipv0, as opposed to that, if I just say cd, regardless of where I am and specify nothing else, it's gonna take me back to that home directory. So it's an easy way to get back to where you want to go to.
7:10And again, if I just do cd hyphen, takes you back into the previous directory, which is this one right here. And again, just to be clear here, if I just want to go into my documents directory, if I just try to do cd documents and to enter, we're gonna see here, there is no directory inside of the locale directory called documents, okay? So it's gonna give me an error. So this is why you have to supply the full path or give the correct relative path depending on whereabouts you are in the system.
Exploring Other Commands
0:00Alright, so let's go and check out some more commands then. So what I'm going to do here is I'm going to go back to my home directory and just press CD. Alright, so here I am back here and if I do a listing we can see all my directories. Now what I want to do is I want to go and create my own directory. Now the way I can do this is via the mkdir command and again if we want to see how to use it we can say man mkdir and to enter and it says here this is the command to make directories. And again if we look at the options we see we have these additional switches such as the dash p flag. So say for example I use this I can also specify the parent directories that I want to be created.
0:34So we'll get to see what that looks like. So inside of here I will say mkdir and then give the name of the directory that I want to create. So let's just call this one testdir, okay. So if I hit enter and do a new listing we're going to see here I now have this new directory structure right here. Now again we just saw we had the dash p flag this allows us to create multiple different sub directories at the time of creation. So again if I just said say for example create directory let's just maybe call this one I don't know let's just say bladder okay I'm running out of ideas.
1:06And inside of this I tried to create a smaller folder let's just call this one subfolder 1 and then maybe create a directory inside that called subfolder 2 that type of thing. If I hit enter here we're going to get an error. However if I arrow back up and I just do the dash p flag to allow me to create the parent directories. If I hit enter now it's going to be accepted and if I do a listing we're going to see here we have the bladder directory so I can go into it. And if I do a listing we have folder 1 inside or subfolder 1. So I can go inside here and do a listing we have a new folder inside and that is going to be subfolder 2.
1:39So we're going to see here this is now where I am in the directory structure. So once again if I just do cd go back to the home directory there I am right there. Now right now we've created some directories if I want to create some files inside these directories I can use the touch command. So say for example I go into the test directory like so do a listing we don't have anything. But if I say touch and just call this one file1.txt and to enter do a listing we have now created that file right here. And again how can we tell if it's a file or a directory?
2:10Well if we use the long listing by doing dash L we're going to see here at the very end when it happens to be a file we're just going to notice a little dash right here okay. Whereas if I do cd dot dot to go back do a listing if I do a long listing notice this right here okay. All these objects bladder all the way down to videos these are all directories because at the very end they have this d as opposed to the hyphen. And again you can see this quite clearly if I create another file inside the home directory this time and to enter do a long listing. We're going to see here this one here doesn't have the coloration and at the end it just has the hyphen so it is a file it's not a directory.
2:46So let's just say I wanted to copy a particular file and move it into another directory. Well right now we have this one right here example.txt let's say I wanted to leave it there but also make a copy of the same one inside let's maybe go with the let's say the pictures directory. Well I can say cd or cd cp should I say for copy then give the name of the file that I want to copy and then specify whereabouts I want to copy it to. And again the concepts of absolute paths and relative paths are still at play here as well. So if I want to just be using relative paths I can just specify the name of the file directly or I could say forward slash home forward slash ipv0 forward slash example.txt.
3:25In this case here we're inside that directory so I'm just using the shorthand. Where do I want to copy again I can just use the relative path and just say I want to copy into the pictures directory. So if I enter do a listing the file is still here as we can see however a new copy of it should also exist inside the pictures directory as we see right here. Now if I want to delete a file i.e. remove a particular file all I have to do is use the rm commands. If I say rm example.txt do a listing suddenly it's been deleted.
3:56If I do cd back to my home directory listing as we can see the original version still exists but we deleted the copy of it right here. Now if I wanted to move a file as opposed to copying it I could use the mv commands. I can say mv example and then specify where I want to move it to so let's maybe move this into the templates directory like so. So if I hit enter do a listing we're going to see here it's gone because it now lives inside this particular directory like so and if I do a listing there it is right there. Now again if I go back to my home directory just by saying cd so here we are right here.
4:28If I do a listing let's say I wanted to delete a folder okay so if I just said rm on tester for example and to enter it's going to give me an error saying this is a directory. So there's two ways in which we can solve this we could say rm dir and just say tester so that means remove directory. If I hit enter what you're going to notice is that it's not going to allow me to delete this directory with this command because the directory is not actually empty. So if the directory is not empty what I want to do is I want to say the rm command but I want to use the dash r flag for recursively delete.
5:03So what that means is delete everything and everything is inside it so if I now say delete tester like so it's going to delete directory as well as everything within it. Whereas just the rm dir command if the directory happens to be empty so say for example I create a new one just called let's just call this john dir there we go right there. It's not got any files inside of it it's not got any subfolders in it so it is just empty so if I do rm dir on john dir and to enter we're going to delete it no problem at all. Now another command we can use to ultimately print text onto the terminal is I can use the echo command so if I can just say echo hello my name is john and to enter what it's going to do here it's going to take this and return it back to me on standard output.
5:46Now the cool thing about this is what we can do is we can actually use this and redirect to output so that it doesn't go on to standard out but instead it goes inside a particular file. So let's just go and create one called I'll just say greeting.txt do a listing so there is a file right now it's not got anything inside of it but what I could do is I could say echo hello my name is john mcgovern pleased to meet you. And as opposed to just you know printing it out like this instead if I actually just take this command and I use the right arrow what it says here is take this particular input and I want you to put it into whatever file you specify and again you can use relative or absolute paths.
6:27In my case here I will just use the relative path so put it into this particular file right here if I hit enter you'll notice it didn't actually print back to me instead the content now is inside this particular file. So the way we can open particular files is by using the cat command for concatenate if I just say cat and then say greeting.txt we should see what is inside this particular file and that's what it is right here this is now written inside of this. And if I happen to arrow up and delete this write in some new content so I'll just say hey my name is Simona.
6:58If I hit enter here you notice the content goes into the file again but the thing is this here has now overwritten what was previously in this particular file so if I happen to cat it again we're going to see here the old information is deleted that has been replaced with the new content. Now if I want to append to stuff that is already inside the text file as opposed to overwriting it I can use my double arrow so check this out if I now arrow up and I just do double arrows and I just say I live in the United Kingdom. If I hit enter here again it doesn't print on the screen but if I happen to look inside this file again and to enter as opposed to this line just overwriting the top one instead is appended to on a second line.
7:38And again as always if you're curious about particular commands by all means I encourage you to read the man pages like for remove as it says right here it tells you what the description is what it actually does and we can see here all of these additional options that you can use with this particular utility.
Filtering Text with Grep
0:00Alright friends, let's check out more commands. So in this case here, what we're going to do first is to look at a text editor. So a built-in text editor within the Ubuntu system is one called nano. So if we just say nano and then give the name of the file we want to be opening or creating, it's gonna effectively open up and allow us to type away as we wish. So let's check it out. If I do a listing, what we can see right here is we have our greeting.txt. If I want to open up in the text editor, I can just say nano greeting.txt and enter and this opens me into this text editor and I can just use my arrows to move around like so and if I want to type away, I can just press return to get a new line and just say this is just some more text and I can just keep adding this as I ordinarily would with a text document, okay? Now if I want to save this, what I'm gonna do is hold down control and then press the letter O. Now we're gonna see here it's gonna say what is the name of the file you want to write. Automatically it's gonna keep the same names. I'm not gonna touch it and just press return. When I do this, it's now written as it says down here and if I want to escape and leave the text editor, I can just press control and then X. So now I've modified this and if I open up the file and look at it, as we're gonna see here, I've now added this additional stuff. So now that comes to us using what is known as the grep commands. Now grep allows us to search for particular patterns in files or in
1:19particular inputs. So let's say we're trying to look for the name Simona in this text file. Now I know clearly we can see that it is there, it's very obvious, but you can imagine this is, you know, maybe thousands of lines long, okay? We're trying to find something. So what I can do here is I can just say grep and then I specify the pattern I want to be looking for. So I'm trying to find Simona. So I'll put that in my quotation marks and then I'll specify the target that I want to be searching through, which in this case here is the greeting.txt file. So if I hit enter here, as we're gonna see here, it's gonna go and highlight any instances of that particular match. So again, if I happen to open this up again, okay, go back in here and let's just add in, let's just say Simona loves working with Linux. Again, I just write it out by pressing ctrl-o, hit enter, ctrl-x to escape. If I rerun the patch, or not the patch, not the patch, the pattern match, it's a bit of a brain fog there, okay? Let's try to run this again, hit enter. As we're gonna see here, we have a match on this line and we also have a match on that line. Now notice this, okay, it's actually printing out each of the lines and not just the word itself. So we can see here, this line prints out and this line, and obviously we can see we get the highlighting, but notice the middle line in the original text document, I live in the United
2:34Kingdom. That is not present, okay? So we're just seeing the match and the corresponding line that the match resides on. Now one thing to note here is that the grep utility happens to be case sensitive. So if, say for example, I go here and I say I want to search for Simona, and I hit enter, it's gonna say well I didn't find anything like that. Now I just said grep is case sensitive, but that's not entirely true, it's just case sensitive by default. If I use a particular option known as the iflag, that is going to go and ignore case sensitivity. And again, how would I know this? I could say man grep to look at the utility, and as we're gonna see here, this is going to print the lines that matches patterns, and if I look at the options and just scroll down, look at this one right here, dash I ignore case. So let's go and try this then, okay? So if I try this again, and I do dash I, I'm saying I don't care about the case. As we're gonna see here, we're now actually getting the matches. We're not actually seeing the line numbers themselves, okay? So if I want to also see this, I can use the dash nflag. I will say search case insensitive, show me the line numbers for any matches of Simona in the greeting.txt file, okay? So if I enter here, it's gonna say here, this is the line that it's on, this is the actual match has been highlighted, it's on line one, and we've also got another match on line four, and
3:52this is the line in which that second match also resides. Now say for example I wanted to just count the amount of matches in a text document, what I could do is I could arrow up, and this time here I'm just gonna say grep for Simona, and I'll say do it case insensitive, and I want you to count the amount of hits that you actually get. So if I hit enter, it's gonna say I found two of these within the actual text documents, whereas if I happen to arrow up and remove the case insensitivity, and to enter it's gonna say I found nothing because we're now searching on case sensitive once again. Now let's say for example I wanted to do an inverted match, meaning that I want to find everything that does not match this particular pattern. So again, just before we begin, let's look at the text document. Okay, so just say greetings, there it is right there, I've got four lines. Let's say I wanted to see all the lines in which Simona is not actually present, so what I could do here is I could say grep, let's do it case insensitive again, and this time I'm going to say dash V, okay, that's gonna allow me to invert the actual logic here, and I'll say I'm gonna search for Simona, and I'm gonna target the greeting.txt file once again. If I hit enter, it's gonna show me the two lines in which Simona is not present, and again if I happen to arrow up and remove the case insensitivity, we should have no matches for Simona, that means we should print out all four lines as we can see
5:09right here. Now let's say I wanted to just search for the actual word itself and not show the entire line, okay, so let's say grep, again let's search with ignoring the case, and now I'm gonna say dash O, that's gonna say only the actual match should be shown here. So again I'm gonna look for Simona inside the greeting.txt file, if I hit enter here, it's just gonna show those particular matches and not the entire line, and again if I want to see the lines that they happen to be on, I can say dash N for the line number, if I hit enter here it's gonna say look, Simona is found on line 1 and line number 4. Now check this out, if I wanted to perhaps maybe have another particular file, another text file, let's just say nano, and I'll create a new one just called, let's just say secondexample.txt, okay, I'll just say my name is John, just say I love Linux, and I'll just also say and I also love Python. Okay so ctrl O to write, ctrl X to escape, so we can see here this is the content of this particular file, we also have the greeting.txt, okay, so let's just search for any instances of the word Linux, but we want to search in two different files, okay, so what I could do is I could say grep for the word Linux, and I want you to search inside the greeting.txt file as well as the secondexample.txt file, if I hit enter, look at what it says here,
6:26okay, it shows me inside greeting.txt, this is the actual match right here, and inside this particular text file, this is the actual match, and again we can keep adding our flags, I can say, you know what, I also want to see the line number, okay, so I hit enter, we're gonna see here, it's on line 4 of this particular file, and it's also on line 2 of that particular file, but it gets better, as opposed to me actually specifying explicitly the files I want to be using, I can also use a wildcard, what I can do here is I can say grep, show me the line number, I want to search for Linux, but the thing that I want to be searching is anything that ends in .txt, so all this represents is anything, so look at the naming conventions, this here, okay, greeting.txt, it ends in .txt, see that right there, so this part here, we're saying it doesn't matter what that looks like, or what it's spelled like, as long as it ends in .txt, we're gonna include it, same with this, also ends in .txt, so by virtue of just shorthanding this, we're actually going to be searching these two files, if I hit enter here, then it goes right there.
Sed and Awk
0:00All right, so we have a few more commands to look at and the next one is going to be the SED command. So let's go and check it out then. So all I'll do here is clear my screen and I'll say man for the SED command. So we can see here this is a stream editor for filtering and transforming text. So let me go and give you an example of that. Okay, so if I press q to quit and do a listing, let's once again see what we have in this greeting.txt file. Okay, so check this out. If I just say SED and within my quotation marks, I say 1p, okay, and then I'm going to specify the name of the file that I want to be operating on. So check this out. If I hit enter, look what's happened. Okay, what you may notice is that we have a duplication on the very first line. Now the reason for that is because when I said SED, I'm saying I want you to print out the first line in this particular file, which is what it's done right here and then automatically it goes and prints out the entire contents of that file, okay. Again, if we just add it up and I say let's go with 2p, what do you think it's going to do?
1:01If I hit enter, what it's going to do, it's going to go and print out the file as well as the second line as well. Okay, so we get a duplication right there. Now in this case here, if I just want to only print out that particular line, I can say "-n". And again, the way I know this is if I go into the man page and I just say "-n", what it's going to do, it's going to suppress the automatic printing of the pattern space. Okay, so as opposed to seeing everything, we're just going to get the match. So now if I just say SED-n 2p, I'm just saying print out the second line in this particular file right here, which is going to be I live in the United Kingdom. Arrow up, let's try 1p, as you expect, it's just going to be printing out the very first line in this particular file. Now say, for example, I wanted to use another expression, let's just say 1d and I just target the particular file, what do you think is going to happen this time? If I enter here, all it's actually done is kind of delete that particular line in the standard output. Okay, so in the printing of the text, but the actual file itself remains unmodified like so. We still have my name is Simona, but we just printed out everything except from the very first line. And again, if I arrow up and I say SED-2d, it's pretty much saying print standard output, but remove the second line, which should be I live in the United Kingdom. So let's go and hit enter. As we're going to see here, that is the one that has been removed. Now,
2:19like I say, when we do this, we are completely unmodifying the actual file itself. However, we do have an option to insert and inject our actions into the file itself. So let's see this, okay, if I just want to say SED and I say dash I and I say, let's go with 3d, okay, and then I specify the name of the file itself. What I'm going to do here is I'm going to target the third line for deletion, and I actually want to insert that into the actual text file itself. So really modify this, okay, so if I hit enter here, as we know, this was the original text file, but if I now cat it again and to enter, look at this right here, the third line, which was this one, this has actually been removed. Now check this out, we can also do more things with SED. Let's maybe say I wanted to replace all the instances of the word Simona with the word John, okay. So what I can do here is I can say SED and then in my quotations I will say substitute and I'll say forward slash and I'll say I want you to substitute the word Simona and then I'll say replace it with the word John, okay, so this is pretty much the format S forward slash what you want to target forward slash what you want to replace it with and end with a forward slash and then again what do you want to be targeting? I want to be targeting this particular file and if I hit enter, what it's done, it's printed the information to standard out, but has that actually modified the file itself? Well, if I happen to open
3:37it up, as we can see, it's not actually done this, so if I want to actually inject that change, what am I going to do? I'm going to say dash I like so and to enter, arrow up, cat it and now the file has actually been modified like so. Now let me just highlight something to you, okay, if I just open this up again and let's maybe on the same line just say I know John is a super common name, okay, which which is unfortunately, so let's just press ctrl o and enter and then press ctrl x to escape, so now what we're going to see here is in this particular file, notice this right here, okay, we've got two instances on the same exact line, so if I try to modify this, okay, now what I'm going to do here, just for simplicity, I'm going to remove the dash I flag and what I'll now say is anytime you see the word John, I want you to replace it with the word Simona. Now the way I phrased this was a little bit inaccurate and you'll see why, okay, so if I just hit enter here, nothing is going to happen because I actually made a mistake there, what I should have done, this is a good learning lesson, always make sure we have that forward slash at the end there, otherwise the expression is going to be unterminated, so let's try it again and look at this right here, hey my name is Simona, I know John is a super common name, sentence doesn't make much sense, I live in the United Kingdom, Simona loves working with Linux, so we can see here on this
4:58instance, John was changed to Simona and we can see here on this instance, John was also changed to Simona, but the other instances on the same line, it didn't actually happen, so what it's doing here, it's finding the match, the first match on that line and doing the substitution, then it moves to the next line and does the search, so it's not doing a global change, instead it's just finding the very first match on that particular line, now if you only have one instance on each line, well it can work as we already seen, but in this case here, not quite so, so what I could do is I can modify the query and I can also add in a forward slash g, now what I'm saying here is that I want this actual expression to be applied globally, which means all instances that you find it, so every time you see a John, I want you to change to the word Simona, so if I hit enter here, now look at this right here, makes much more sense, hey my name is Simona, I know Simona is a super common name, which it's not, it's a very unique and lovely name, unlike John, and it says I live in the eddy kingdom, Simona loves working with Linux, now again, if we just look at the text file itself, that has been undisturbed, it's not changed, but what I can do, as we know, is I can go and actually inject it directly into the file with the dash i flag, if I hit enter here, all instances of John have been changed to
6:15Simona in the actual text file, so if I happen to open up one more time, there we go right there, so that's how we can do that with the said utility, and the next one we're going to look at is the awk utility, which is an awkward name for a file, for a file, for a command, so let's say man awk and to enter, as we're going to see here, this is going to allow us to pattern scan and process language, now in this case here, the benefit of awk is really in using structured data or working with structured data, things like comma separated value files, excel spreadsheets, that type of thing, when you have things like columns, you'll see why, okay, so if I press q to quit, all right, so let's maybe create a new file just called info.txt, okay, it doesn't matter so much, and let's just say the first column can be John, I'll specify my location is in the UK, and I like to teach Linux content, okay, then we'll have James, James is in the USA, James likes to teach Windows stuff, and we'll now go with Lalo, Lalo is also in the USA, and Lalo likes to teach Cisco stuff, and we'll have Simona, Simona is also in the UK, and Simona likes to teach CompTIA stuff, okay, so right now what we have here is a text file which is kind of structured, okay, so the first column right here, this is all the names, and do you know
7:30what, let me get a bit of a thinner pen for that, it's a little bit ugly to look at, so the first column here, this is just names, then we have a new column, which is going to have all of our locations, then we have this last column here, which is going to be kind of like their specialities, okay, okay, now again it's not the prettiest to look at, but it is structured in some kind of way, so let's try and manipulate it using awk, so what I'm going to do here is press ctrl-o to write, ctrl-x to escape, here is the text file, and we're going to operate on it using awk, so I'm going to say awk, and I'm going to have my single quotation marks like so, and then I'm going to say in my curly braces, what I want to do is I want to print, and I'll say $1, now what I'm doing here is I'm saying print the first column, okay, so check this out, if I enter here, nothing's going to happen, because I'm going to have to press ctrl-c to interrupt, I forgot to specify the file, which is a bit silly, so try this again, info.txt, and to enter, look at this, what we're getting here is just the information from the very first column, and you can imagine if I go up here, and I said you know what, make this number two, we're going to get all the information in the second column, and again, arrow up, we can see three, we get the information in the third column, and if I try number four, as you may expect, we're not going to get any information, because we've run out of columns,
8:49so what I could do, is I could add information and concatenate this, okay, so check this out, what I can do here, let's say awk, and I'll say print, and then I'll have my quotation marks, I'm going to say hey, my name is, in my quotation marks, and I'm going to go and add in dollar sign one, then I'm going to have my quotation, have a space, just say I live in, and then I'll have my quotations, and I'll say dollar sign two, and then I'll say and I love teaching, and then I'll say dollar sign three, so now I will close my curly brace, and then close my single quotation marks, and then I'm going to specify the file that I want to operate on, which is going to be info.txt, if I hit enter here, look at this right here, we're now saying hey, my name is John, I live in the UK, I love teaching Linux, then it says hey, my name is James, live in the USA, love teaching Windows, so all we're doing here is substituting in, in each instance, the first column, which is all this stuff right here, then we go in, substitute in the second column, like so, and then finally, we go and substitute in the third column, as we can see right here, and once again, as we know, what we can do is we can redirect the output and put it into a text file, let's just call this trainers.txt, if I hit enter here, doesn't print out, but what we've done here is written this
10:07into a little text file, like so, and then of course, what we can now do is do things like grepping for this, okay, so I can say grep for the UK, in trainer.txt, if I hit enter here, as we can see right there, we've searched for it, it's now in a text file, nice and neat.
Using the Pipe
0:00Okay so the last command that we're going to look at in this particular skill is the pipe utility and that is this little arrow here little arrow what am I talking about this little symbol here that's like a straight down line okay this is the pipe symbol now what this does it allows us to take the output of something and then feed it as input into something else now again this sounds pretty weird when I say that but as you see examples it should become a little bit clearer so let's just do the examples and dig in so check this out think about it let's say I would like to use the grep filter but I don't want to grep on a text file I want to grep and maybe the output of a particular command so for example I say cd into the root directory and I'll go into user and I'll go into let's say bin do a listing and let's just maybe say I wanted to find something inside this particular directory okay let's just maybe say python okay now right now as we can see there's quite a lot of stuff here so it might not be so obvious if we happen to have this particular thing so what are we doing here we want to do a listing so we'll do a listing in fact you know what let's do a long listing so here is all the stuff right here and if I want to now filter this I can issue this command take its output and then use the pipe symbol and then feed it in as input into something
1:16else so now what I can say is take the output of ls-l and then use the grep filter to filter for the word python okay so now if I hit enter here check this out here are all of the things in my directory listing that actually match this particular pattern so we can see here here are all the python outputs inside this particular directory so that's an example okay all right so let me go and show you another example and we'll use a command we've not actually seen yet okay so if I say ps and I say aux or aux what I'm going to do here is show all the processes on my system with the ps command and these options here aux allows us to see all the processes for all users I want to see it in a user-friendly format so we'll see things like cpu and memory usage and we also want to see processes that are not actually attached to the terminal so all background processes background services that type of thing so if I just enter here check this out we get a ton of information coming on the screen like so okay so this command shows me a lot of stuff now again let's say I wanted to use the grep filter on the output of this particular command how would we do it we're going to use the pipe to take this particular output and feed it as input for the grep filter so let's just say in this output obviously we can see it right here but let's just say I wanted to find out where bash
2:35is in my processes so we can see here here it is with the process id of 18965 so what I could do here is I can say psx and I'm going to go and grep for bash like so and to enter as we can see right here this is the output and we can see we found it with the process id of 18965 so now I've found the process id if I want to kill that process I can say kill minus nine and then give the process id now that I've found it I can say 965 and to enter what we're going to see here we kill the bash terminal straight away so clearly as we can see right here the actual use of the pipe utility what this does it allows us to take the output of a particular command and feed it as input into another command again it doesn't just have to be grep filters we can also use other commands all right so let's say for example I want to create a little file full of passwords okay so I'll say nano passwords dot txt and let's just imagine that inside this text file you had a dump of people's common passwords so let's say someone's got a password called password1 let's just say someone's got mypass someone's got jonpass someone else is also using password1 which is pretty bad someone's got a bit of a better password with this one right here okay try a little bit better all right also check this out okay let's just save this like so we have our little file that's got a
3:53password dump in it now let's say we wanted to take this and we wanted to sort it so that it's in alphabetical order and also to remove any duplicates so what I could do as we saw is we can use cat passwords to actually output the contents here and then what I can do is I can take that output and use it as input into the sort function okay so if I just say sort like so what we're going to see here is we're going to get it in alphabetical order so we can see abcs at the top and again this gives us output the output is now just sorted but once again we can pipe that into yet another command so if I just say sort and then also pass it into the unique function if I hit enter we've now taken the output we've sorted it so that it's alphabetical and we've removed any duplicates so no longer are we going to see the duplication of this particular password indeed instead we only have one instance of it
Validation
0:00Alright friends, so let's go and validate what we learn within this skill. Alright so the instructions are to launch the lab below so let's go down here and just choose to launch this like so. Now in the meantime what we're going to do here is wait for the VM to load but once it has loaded we're going to go and double click on the Ubuntu 1 shortcut on the desktop and that's going to go and open up an Ubuntu virtual machine. Now after that I want you to open up a terminal window and perform the following actions. So I want you to print the current working directory first and then after that I would like you to go and list its contents. Then I want you to create a folder called validation folder and then change into this directory. Now once you've done that I want you to create a text file inside this directory and call it validation.txt and then use the nano text editor to edit this file and enter the following text. You're just going to say learning Linux is fun and then we're going to go and save the content and then exit the nano editor.
0:57Now after this we're going to go and use grep to search the content of this particular file that you just created and we're going to look for the presence of the word Linux. Now we want to ensure that the grep search is indeed case insensitive okay so make sure we do that. Then after that we're going to use sed to substitute the word fun which is this part right here. We want to substitute that for the word awesome and we want to ensure that the content inside the text file itself is modified okay so very very crucial. And then finally after everything we want to go and navigate back to our home directory and then validate or rather validate delete the validation folder directory including all of its contents. So friends go build up your lab give it a go and I will see you in the very next video where we discuss the solution.
Validation
0:00Alright friends, so let's go and walk through the answer them. So what I'll do here is go to my lab environment and I'm going to go and click on the Ubuntu 1 virtual machine. So just double click this like so. And all I'm going to do is to collapse this to get a bit more space. Now just give this a moment to load. Alrighty, so it's beginning to connect to the VM. So what I'll do here is just full screen this, okay. So what I'll do here is let's just go up and click this and we'll search for terminal to find the terminal app. There we go right there, click here. Alright, so as it says here, the first thing we're going to do here is to print the working directory.
0:32So that's just going to simply be pwd, print working directory. Let's enter, as we can see here, we're in the home directory for the learner user as we can see. So now we're inside this directory, we're going to go and list its content. So we can do this by just typing the ls command and we can see here all of the folders within. And if you so wish, you could also do the long listing, either which way is going to be a-okay. So then next thing we're going to do is to create a folder called validation folder and then change into this directory. So as we know, what I can do here is say mkdir validation and then we'll say dash folder.
1:05And then we'll just cd into that particular directory. So as we can see, we're now inside of it. Now we're going to use the nano text editor and enter the following line. Okay, we're going to create this file validation.txt. So inside here, I'll say nano validation.txt and to enter. Alright, so let's just say learning Linux is fun. And to save this, I'll hold down ctrl, press o and then hit enter and then press ctrl x to escape. So now I'll use the grep utility to search the content of that text file and search for the presence of the word Linux and ensure that the search is case insensitive.
1:40So what I'll do here is I'll say grep and I'll say grep for Linux. And like I say, if I just did validation.txt and to enter, it's not going to find it because I've done lowercase right here. But if I just say, you know what, I don't care about the actual casing. And I just say dash i to ignore the case. And now I hit enter. What we're going to see here is we actually do have a match, even though it begins with a capital L. Alright, so next I'm going to do here is use sed to substitute the word fun for the word awesome. And we want to ensure that the content of the text file itself is indeed modified. So what I'm going to do here is I'll say sed and I'm going to say dash i to actually insert the changes.
2:14And then in my quotations, I'm going to say substitute the word fun for the word awesome. Now again, if you so wish, you can add on the forward slash G for the global conversion. But either which way, because there is only one instance, we don't have to care about that. If I just close off my quotations and say I want to act upon the validation.txt file. If I hit enter, now it's going to go. And if I do a listing, the file is still there. And we want to make sure that the file is modified. So let's use the cat command to open it up. And as we can see here, we have indeed modified the content to say learning Linux is awesome.
2:45Alright, so the next thing we're going to do is to navigate to the home directory and then delete the validation folder as well as all of the contents. So let's go back to our home directory. The shortcut we can do is just press sed. That takes us back to our home directory. As we can see right here, if I do a listing. In fact, you know what, let's clear the screen and do a listing again. As we can see, we have the validation folder. To remove it, what we're going to do here is say rm-r for recursive deletion. Because if we just do rmdir, just for clarity if I do this. And we do have content within this folder.
3:16And to enter, what it's going to do here, it's going to say it's failed the actual action. But if we say recursively remove and then specify the validation folder. And to enter, now we're going to see here the folder is gone as well as the text file within it. So friends, that is us for our validation challenge on the Linux CLI. I hope this has been informative for you. I'd like to thank you for viewing.
Frequently asked questions
What Linux commands does the Understand Linux CLI Fundamentals lesson cover?
The learner on your team practices navigating the directory structure with pwd, ls, and cd, then creates nested directories with mkdir -p, files with touch, and removes empty directories with rmdir. The lesson also covers redirecting echo output into a file, editing files with nano, case-insensitive searching with grep, and using sed to print specific lines and substitute text so the change is written to the file itself.
How long is the Linux CLI fundamentals lesson and where does it fit in the CompTIA AutoOps+ (AT0-001) course?
The lesson runs 57 minutes and opens the CompTIA AutoOps+ (AT0-001) course, which totals about 28 hours of video per learner plus lab time. The trainer starts with command line utilities because they are the foundation for the scripting, Git, infrastructure as code, and CI/CD topics that follow.
Who should take this lesson, and what experience does it assume?
The course is intermediate and is aimed at systems, cloud, and network administrators who already have infrastructure experience and are moving into automated, pipeline-driven operations. IT Directors and Team Leads can use this lesson to give those practitioners a shared Linux CLI foundation before they move on to automation tooling.
Does a team member need their own Linux lab to follow the lesson?
No. The course provides a lab environment with two Ubuntu machines, so learners can practice every command even without a home lab, and CBT Nuggets Virtual Labs support hands-on practice when no local environment exists. The trainer also recommends building an Ubuntu virtual machine with snapshots so configuration mistakes can be rolled back safely.
Which Linux distribution is used in the AutoOps+ command line lesson?
The demonstrations are built on Ubuntu, which the trainer describes as a friendly entry point. The commands shown are applicable across pretty much all Linux distributions, so the skills carry over to the environments your team already runs.
How does the lesson confirm a learner can actually use these Linux commands?
A validation lab has the learner print and list the working directory, create a validation folder and a validation.txt file, edit it in nano, and run a case-insensitive grep for the word Linux. They then use sed to replace fun with awesome directly in the file, return to the home directory, and delete the folder with all of its contents.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
Free training library
More free lessons in CompTIA
CompTIA
Explain the Project+ Certification and Basic Concepts
Free lesson from CompTIA Project+ (PK0-005) · 51m
CompTIA
Identify Types and Categories of Security Controls
Free lesson from CompTIA Security+ (SY0-701) · 51m
CompTIA
Understand the Point of Servers
Free lesson from CompTIA Server+ (SK0-005) · 1h 4m
CompTIA
Using Reference Models
Free lesson from CompTIA Network+ (N10-009) · 1h 27m
CompTIA
Explain Cloud Principles
Free lesson from CompTIA Cloud Essentials+ (CLO-002) · 57m
CompTIA
Web Application Vulnerabilities
Free lesson from CompTIA Pentest+ (PT0-003) · 55m
$59
seat / mo, billed annually
