Time
6 hours 20 minutes
Difficulty
Beginner
CEU/CPE
3

Video Description

File Editing in Linux This lesson covers file editing. In this lab based lesson, participants learn step by step directions in file editing. This lesson covers: - Creating a simple text file - Simple file editors - How to move things in command mode - The VI File editor - Input mode - Command mode

Video Transcription

00:04
Welcome to Cyberia. I t I'm Greg Stewart on your subject matter expert for Lennox Plus,
00:09
in part for module three, the systems administration module. We're gonna be covering file editing. So we learned in the past part in part three, we learned a little bit about
00:20
I actually learned a lot about how to create files, make directories
00:24
learned about the permission set of the file. And now we're gonna learn how to edit any of the files that we have. So file editing comes into play a lot as a systems administrator, and you're going to have to edit file such a cz, the etc result dot com,
00:38
etc. Network system, fig or assist config network,
00:41
etc. Host files commonly gets edited adding host names to act as your D. N s. And there's a lot of other files that you can edit. There's many files. If you need to edit a script that's actually in a text file, you can do that before launching it.
00:55
So understanding the file editor is a very, very good skill to have.
01:00
And it's one of the skills that, to be honest, has a very steep learning her.
01:04
This is not like your standard editing that you do in a note pad document or a word document.
01:11
You're doing this. You have to remember that you're doing this all from the command line. So it's a little late, like, slightly more difficult than you,
01:19
then you how you ended things and windows.
01:23
But if you're here in your systems administrator than you, you surely want to learn about how to do this. Become good s. So I'm gonna give you the basics and help you to understand how to become
01:32
good. It's a good file editor inside of Lennox Window.
01:36
So we're back at the L A X box, and I'm gonna blow it up again.
01:41
Okay, I want I'm looking at here is my, um
01:45
is my terminal window
01:46
back of my Lennox test top.
01:49
And what I've done is I've actually created a file for us to look at that. We can play around with it,
01:56
Otherwise, we're gonna create some other files as well. So let's jump into it. Let's jump into it from me. Ah, simple point of view first and just create a simple text file and again for this one. I'm just gonna do the cat command
02:09
with the greater than signed.
02:13
I'm actually gonna drop this. Let's let's leave it here in this director's cat
02:19
greater than
02:21
and I'm a name. This
02:23
test file
02:28
text.
02:30
I'm sorry.
02:30
Don't text
02:32
now. It's dropped me into editing mo here. I'm gonna start creativity. So I'm just gonna take this as this is a test file.
02:39
You're learning about
02:44
editing.
02:45
Relax,
02:46
violating Alexis put there,
02:53
and I'm a hit interests a couple times in the control d to get out of that mood and to say into right way
03:00
saved to the disk.
03:02
So let's check our permissions on that.
03:06
It's doing L s Dash fell
03:07
and the file name, which is test file.
03:12
Thanks.
03:14
And it looks like I've got Reed right
03:16
as the owner of it. And everybody else just has to read. I'm fine with that. For now. You could change if you want to have rewriting, execute, but we could do everything we need to do. Just rewrite permission through this file.
03:28
So I'm gonna lead the file commissions alone and really just jump right into editing this file.
03:32
So there's several. There's a lot of different file editors out there for Lennix and you can download several when you feel comfortable with what I originally used when I was learning, Lennox was following her to call them be. I am.
03:46
And that is just a different version of the V I editor v. I stand in Lenox V. I stands for It's the editor actually stands for visuals. Just takes the first to be in the eye from the work visual.
03:57
It's a visual editor allows you to go in and edit thought of files at things, change things to lead things and then save it and right back to the desk, all within the command line
04:05
without having to go through the hassle of opening the file on the goofy
04:10
typing it, saving and closing et cetera. Just doing save as you could just do it all from the command lasting or have to jump back out.
04:16
And then again as a reminder if you're you know, if you're in a situation where you need to remote into somebody's machine and you're using sssh client
04:26
terminal client, something like putty and you're gonna need to know how to do file anything from remote workstation.
04:32
So V I stands for visual so if them or B I am is very much improved in the eye. Improved
04:41
man. Just take some of the characters strings together
04:44
Them is a little bit different. Started off using them, loved it. And then I got to using B I and I've become proficient with B. I was also Nano and a couple others that you can download out there and I'm gonna let you google around, find which file it. Or do you think you
05:00
you feel most comfortable with Google? Find some of the websites with the file editors on it. You can see what the differences are again. Lennox is a community of users that, you know, improve the system on a daily basis
05:13
so they may come out with a new final editor on a daily basis. You never know. So they just made up improve and upgrade the current by letter that using
05:21
the purpose of this course, I'm going to be focusing on using the V I editor and I'm gonna show you how to use that.
05:28
So to get into V, I you have to simply use type V I
05:31
that doesn't actually take you anywhere you need to file May
05:35
someone to be I test file
05:39
and dropped me into my file editor
05:42
and you could see the very top shows. My first line of text. This is a file we're learning about violating in Lenox.
05:48
So what can I do from here? If I start just typing things, it's not going to really do much for me, cause right off the bat when I open a file and v i n the editor, it's open and was called command mode, and this moment is just strictly command mode. I can use some of the keys on my keyboard, too.
06:05
Jump around in different positions in the file. If it's a super long file, it's helpful
06:11
to be able to do that.
06:13
If I type a just, ah, lower case K, it takes me to the next character,
06:17
and then I can start typing immediately. Okay, But I want to do that.
06:26
So I'm gonna back spaces. I'm actually gonna hold on to escape this
06:31
and I'm going to
06:41
I'm going to accept this mode.
06:45
Yeah,
06:46
about saving anything.
06:50
Yeah,
06:53
and I'm going to clear and I'm gonna open that back up Since I messed it up.
06:58
I want to make sure we do this the right way. So the eye test file
07:03
case, We're back. So thio the commands that we can use
07:10
in command mode? Very. And what I've done here is I've written up a
07:14
instead of using a slide, I've written up
07:18
a file here to show you some of the different components. So I'm gonna put these side by side
07:26
this just slightly, a little bit smaller.
07:31
You sit here.
07:38
All right,
07:39
So
07:41
while in command move.
07:43
I could move around so I could go if I had a choice to move one character to the left
07:47
on the current line that I'm on, However, I'm in the furthest left. Most character. At this point in time,
07:53
Jay moved down to the next, moves down to the next line
07:57
and you can see that I can't go any further. Those little teal days was little symbols there.
08:03
That is the end of the documents. Just two lines at this point time. Because remember, I hit enter after I did the line cup to interest to get four to control D.
08:13
So I can't go any further. Okay, so but if I go back up
08:18
I want to move up to the previous line. A hit kay that takes me back up to the previous line again. J goes down warm, Okay, Goes up one.
08:26
I'm not sure the logic or reason behind what these keys hot keys are, why they're named what they do.
08:33
Not really concerned about it as long as you know what they are and what they do. Which is why there's a pretty steep learning curve when it comes to filing. And Lennox,
08:41
there's a lot you have to memorize and understand ableto navigate the file and we're starting out with super simple file here. This is two lines. He imagine having a file or ah, script with, like, 3000 lines of code. I mean, it would be it would be really difficult to get Get around the file. So you have to understand
08:58
different honkies. J and K take you up down one file line.
09:03
Um,
09:05
move right. L moves me right. One character. I could go. One character timeto right. H goes back to the left.
09:13
I'm not sure why l wouldn't be left, but it's actually right. So there's some things for slightly confusing. And if I just want to go to the next word I hit. W takes me to the next word on the current line. Tell me you got to come to you
09:26
and why we're doing this. Why? There's even a command mode, because instead of story having to start the very beginning Once you go into editing mode, which we're gonna get to next,
09:35
you can go and put the cursor wherever it is that you want to start. Because you remember. You have to know that
09:41
you can't use your mouse in the command line to drop the
09:45
cursor wherever you want it to start. So you gotta use the keys to go around.
09:50
So I'm gonna go back.
09:52
Yeah, to the very beginning.
09:54
Okay, Um, and then moved to the previous move be would be moved to the previous beginning of the word on the current lines. Let's go. Word, word, word, word, word. And I'm gonna go be takes me back.
10:07
Takes me back to the first word of the previous first layer of the previous word.
10:11
Um e moves to the end next end of the current line. Next. The end of the word on the current line. Okay,
10:18
so I printed this document up. Firing drew up this document so you could see visually see some of the things on there that will help you to get around the file. The V I file editor.
10:31
Well, let's look at a couple more
10:33
control F control dash lower case f You could scroll forward one patient again, right? I don't have a long enough. I'll thio be demonstrating this, but we're talking like code files with 3000 lines. You could go off a page at a time instead, instead of line by line
10:52
G moves to a specific line on your file. So if I type and let's go back over here,
10:58
go back to the very beginning
11:01
and I'm gonna take in
11:03
three. H would move Meteo. No, I'm sorry. Three of three g or four Jeanne moos me to the fourth line, but I have four lines, so I'm gonna do to g
11:13
uppercase. And that took me right down to the next line again. Not a great example of this file. And just try and get you some of the different items that we get to a longer father created specifically for this task.
11:26
Okay. And there's some other ones. H moves relative to the top of the screen. Three actual movie to the third line from the top. L will move you to relative to the bottom of the lot of the screen.
11:37
So three l a movie to the second last line, three hour movie to sector last line. Extreme
11:43
too. Well, actually, as a typo.
11:46
Okay,
11:48
um, and getting out of the ice. So once you're done, you're edited and all, You've got to be able to get out of it like a shows. Earlier when I made a mistake, I was trying to get out. Well, it's making it saves.
11:58
I'm basically gonna hit my escape key. That puts me in an escape. Keep with you in the command mode
12:03
and I'm going to do a colon and you could see my cursor dropped to the bottom of the screen. It's flashing their I didn't call him.
12:09
Now it's gonna be asking me to call for a command to accident. Knows that I'm in a move or I'm gonna start. You're gonna win it to get out of the editor.
12:16
So if I just do a Q
12:18
and A bang,
12:20
exclamation bang! And Lennox
12:22
that's going to quit the editing and is going to do without
12:26
committing any of us say of any It's not committing any save to the file, and he changes I made is not going to commit. So what I want to do is I'm gonna do use that one if I've made a mistake and I just want to get out and then get back into it. The file. How original Iwas We don't mess up anything.
12:41
Okay, so I'm not gonna do it so we can show you all w
12:46
with a bang hit. Enter on that one.
12:48
You can see here at the bottom Mrs Text filed testified about tax. There's two lines and 67 characters written
12:54
okay, and I and I've made ah, that's basically my safe. But so if I'm in in the middle of editing a really large file, you want to make sure to do that, you know, escape and then colon,
13:07
right? With bang as you're safe, it's gonna save everything that you've made so far without closing the file. Okay, this is also I apologize. Bonuses. This type of as well just commits the changes that you've made
13:22
Z Z writes the file Asbestos currently edited and then exits. So it's just basically making a save and then getting out. Capital G Capital Z
13:30
e Bang actually reloads the file, killing any of the changes that you made and then the colon with a bang just by itself. You can actually run Shell Command than the Ender, and it will do that and I'll show you the output up as well. So there's lots of different ways that you can get out that it's safe.
13:46
Well, I generated when I used most of the time which was listed in this document. Hit the escape key
13:52
going rate. Quit with a bang
13:56
that's going too right what I've done and it's gonna quit.
13:58
Let's go back into it.
14:01
Believes easy.
14:05
No, it's not another command. So it's not an editor. Commanded a bun, too.
14:09
But you may be using little red hat or Fedor sent Toss, and that would be economic use there
14:13
in the bun to is gonna be right quit just as I suspected. So you right quick
14:20
and, um, out You could do right. Quitter. Right. Quick bang. Depending may throw an area that says, uh, this file. You know, I'm a ***. Weird air. If you do a bang him just right, quit and avoid the air and get out.
14:31
So let's look at
14:35
what a large file would actually look at what actually looked like and how we can use to jump around and how those
14:41
items that we have in this little text file here would actually help us navigate a larger file.
14:46
So
14:50
what I did is I created a document that is, I didn't actually created myself a copy from a Lennox page that
14:56
I've talked about. It was a basically a short bio on Linus Torvalds and what he's done having group excited us. Let's take a look at that. It's the Linus t dot t. Eckstine.
15:07
So again, I'm gonna do V I to get into my editor. Remember? I could do cat just if I'm gonna look at it
15:13
but not edit it. Right?
15:16
So it was just I did a couple paragraphs, but I want to read it, so I'm gonna do clear first.
15:20
I'm gonna do V I minus two text has dropped me in. And as you can see, the very first line of the very top player
15:28
you can read through it. Last Tour holds is the world's most famous computer programmer and also its most famous fan. This is obviously biased. This comes from a Lennox website called Lin Foe.
15:37
You can see here on the very last line I put taken from www dot info dot org's
15:43
four slash Linus dot html. This is not my own work. Just wanted to get something that was a little bit lengthier than the light created.
15:50
They won't have to come up with a bunch from off top my head to fill an editor. So here we are in the 1st 1st line limit and never if you do in L. A. You're moving to the right one character of time doing h
16:04
I'm moving to the left if I do a J and could move down the line
16:11
down to the next next line.
16:14
Okay, moves up
16:17
Now, once on about this is what you've seen here, right? Remember how I created this file?
16:22
A trade of this file, using the cat
16:26
command with the greater than sign and giving a name? What does this Trust me into that cat Editor what that's doing is that unless I am type What I did here was, I just kind of apparently typed
16:37
as I went. It just went to the end of the line onto the next one. You can see we're operating here. This shouldn't. This is not proper oration have looked like this or that. You see, that just goes to a T. That's because the editing that I did there was not
16:51
basically, you know, didn't have word rap on it. It just kind of went around, Went around, didn't actually split like it should.
16:57
So when you're in that cat emoji to actually hit, enter in the end of everyone, you're typing to get to the next line. Otherwise it'll look like this. Remember that J and K
17:07
bring you up and down one line so it sees this whole first paragraph. It's one line. That's why I'm skipping ahead
17:12
entire paragraph here
17:15
so things to think about,
17:18
then you also
17:19
if I want a stiff, I'm here on this beginning. L and I want to get all the way to the right as far as I can if I want to get to work. Programmer.
17:29
All right, No, we fix this here. Hold on. One second. One fixed. This
17:33
only gets the word programmer, but I don't want to do it.
17:37
One character at a time. Okay?
17:41
I can go to just W which will take him to the end of each word.
17:48
Move to the next word on the current line.
17:52
And that programmer.
17:53
Now, if I want to start editing, I have to get into edit Moto have to type I or in for input.
17:59
Now, I could start typing and actually wanna delete this on to make it a p
18:03
capital P
18:06
if I want to go back,
18:07
okay. And so it's a shift here.
18:12
Student escaped its command mode
18:15
and I wanna do
18:18
quick.
18:19
Yeah, right. So must do a quick bang.
18:22
I want to go back in,
18:26
get funky at times. So I'm gonna go
18:30
w get to the first letter of wars programmer,
18:33
go and actually, and I'm gonna I get into input mode
18:38
and I can start editing.
18:45
I don't want to add more.
18:49
Okay, that's obviously by doing that investable paragraph and everything, but I'm just giving you an idea of how you get in at a file.
18:57
I want to go back to command mode. I have to hit escape. So I just try to hit Q to quit or w two right. Quick acquitted. She's gonna actually type out front right quick.
19:07
Don't do that. So I'm gonna go out and get out of that.
19:11
Okay?
19:14
So now that you've seen what file editing can do, I'm going to make your right. Actually, I don't want to do right quick, so I want to mess up the file. They're just gonna do a quick bang to get out without saving anything.
19:26
So that's file editing with V I. It's fairly. It's a It's a good tool to learn to use you as a system administrator again. Like I said, you'll have Thio edit too many files at sea host files one of the major ones like we talked about.
19:38
And there's lots of filing that you can do and learn. And again, this would be, uh,
19:44
um, I'll put this up here for a minute. You can look at it, but this is basically what you want to do. He composite at this point, and Scrabble have scribbled down all the commands that I put out here so you can understand better how to use them, memorize and get into where they're just second. A tree. You can get zip around a file that's super long, and so it doesn't take much time.
20:03
So that's file editing in a nutshell. With using B. I Like I said, there are many other command. Our file editors out there
20:10
choose one is your preference.
20:12
Do you like them? Ben was a little bit easier to navigate around. I've become for showing the eye. So I stick with the I
20:18
I would caution you to just stick with what you're good with. If you get to a system that doesn't have the eye, you can always reach out. Downloaded If the firewall ports on block, man. So that is file editing, and that is part end of part three.
20:32
I'm sorry, Part four of Module three,
20:34
and we will kick off the next part here shortly. Thanks for watching

Up Next

Fundamental Linux Administration

An open-source operating system modelled on UNIX, first released by Linus Torvalds in 1991. Why do I need this Certification? With the increasing popularity of cloud based systems and data centers, organizations need system administrators

Instructed By

Instructor Profile Image
Greg Stuart
Instructor