Linux (part 3) - Directories, myfile and Nano

Video Activity

This unit teaches how everything in Linux is a file and it goes through the steps of how to create a file with commands such as myfile. The unit also shows how to create a directory and how to copy and move files into a directory. The unit also discusses Nano, which is an editing tool you can use to edit text.

Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
14 hours 26 minutes
Difficulty
Advanced
CEU/CPE
15
Video Description

This unit teaches how everything in Linux is a file and it goes through the steps of how to create a file with commands such as myfile. The unit also shows how to create a directory and how to copy and move files into a directory. The unit also discusses Nano, which is an editing tool you can use to edit text.

Video Transcription
00:04
All right, so let's see what else? How about files? Files were pretty important, right? So go ahead and exit out of here. Go back to being route.
00:15
Well, if she did at home.
00:17
Georgia have all sorts of nonsense in the root directory, as do you. If you set up this way, added some more stuff to it. So
00:27
you're in the set up. So let's just get a clean director here. Since we created the user. Georgia
00:33
Directory in the Home folder
00:36
puts the CD there, so we have a nice been clean space. The work with So everything in Lennox is going to be a file.
00:43
Absolutely everything a device drivers Asyl just is a file for user's file everything to file,
00:51
so I could be a little bit confusing. But in last year, I guess doing the next system programming you'll never even notice. So you don't have to worry about it.
01:00
So let's create a file
01:02
more. Traditionally, we think files is like binary or hex or
01:07
text or something we can work with, or that the operating system works with. Let's just create a little text files. One way to do that is the touch command. Those call it my file
01:18
Nava doing l s There's my file was created and also create directories
01:25
emptied er directory that I was called out My directory
01:30
Never do in L s u Directories Blue That's gonna be directory. And then we have my file.
01:37
We counsel first CD into my directory
01:41
blank right now, and we can course move files around as well. We can copy them, which will keep the original file in place.
01:51
We can also move them, which will delete the original and put it in the new place.
01:57
Who, for instance, if we wanted to take my file from home, Georgia and put it in home, Georgia, My directory
02:02
we could with the CP command. Copy it again. That'll keep the original file
02:08
on DDE.
02:10
Make a copy here in my directory.
02:14
Remember, it's in the parent
02:16
so we could do dot, dot, slash to move back to home. Georgia.
02:21
You grabbed my file.
02:23
Do it dot
02:24
to place it here.
02:27
But also we don't have to use those dot dots if we don't want to. That's a little bit confusing for you. You can always just do the full path if I want a copy home.
02:36
Georgia,
02:38
my file. I could do that so I can be. But the absolute passes what that's called instead of the relative one relative to where I am or absolute from the route. Either way, work whatever is more comfortable for you. I'm gonna put back and forth honestly.
02:53
And then again, the dot could be here. But we could make that absolutely as well. We could do home,
03:00
Georgia. My
03:01
directories can tab complete, which is nice if you're about as good a spellers. I am.
03:08
Who? Home, George. You're my directory. My,
03:15
by the way, it works. So that brought my file here.
03:20
But since we're you C p for copy that did keep the original my file in place.
03:25
So we can also d'oh in the fur move. So that will again delete the original one and move it to the new falling
03:35
Something moved my file to my file too.
03:39
But basically that just renamed it
03:43
since we moved from
03:45
one vial name in the directory to another one. So all we really did there was rename it. Of course we could as we did with the CP moving to a different directory. We can also remove files. So we saw that our em dash rs to delete the entire file system. We could do that with the single file like you do in our m
04:03
my file, too.
04:05
And that's why I was gone.
04:08
Possibly we could get it back with some digital forensics. Or maybe you want to take your friend's ex course. There was nothing in it anyway, so no exciting.
04:16
But
04:17
finding people's deleted pictures and such is
04:21
funding for forensic analysts do
04:26
so. Of course. Maybe we do want to actually put some text into a file.
04:30
So let's start with the echo commands. So echo say, hi, Georgia
04:38
that
04:38
prints out hi Georgia onto the screen.
04:42
So let's do Echo Hi, Georgia on, then a greater than sign.
04:48
Put that into a file. We'll call this one my file again where I deleted my file, but I moved it to my file to deleted my father, too. So let's just recreate my file
05:00
echo hydrogen into my file.
05:02
So that time it didn't prove anything out to the screen. All of the output went into my file
05:09
so we can use a command called Cat
05:12
course would always used man pages. Cat is short for can cat Nate filed and print on the standard output.
05:19
I am using cue to get out of the man pages. I'm not sure if I said that a cue to get out of the man pages.
05:27
Quit looking, cat. My file
05:30
says Hi, Georgia.
05:33
What if I do echo hi, George again
05:39
into my files?
05:41
If I do it, Kat,
05:43
my file
05:45
just Hi, George again. But hi, George isn't there anymore? It overwrote what was previously in that file. The mayor may not be what you want. Sometimes we might want to append to a files, keep authority there
05:58
and his ads and texted the bottom
06:00
How we can do that.
06:03
It's a hydrogen. Third time this time I want to put double greater than sign. This is going to tell it to upend. So it's going to put hydrate 1/3 time at the end of my file.
06:17
Sure enough, Hydrogen again. And hydra 1/3 time
06:23
course. We might want to do a little bit better than this.
06:27
We might want to have some real text editing going on and see how this would be a really annoying way to create a file.
06:33
There are actually a few different text editors for Lennix on. Honestly, I've never seen people fight quite so much about anything in computer science as which text editor is the best in the next.
06:46
I personally prefer Nano. A lot of people laughed at me about that because they like the I better them or heaven forbid g at it
06:57
or you Max. But
07:00
some people really like the ice and really like Nano.
07:03
I like Nano. I actually started in the eye. But I like Nano
07:09
primarily because I do a lot of things like this where I'm
07:12
making videos and if I screw it up, I just lose what, 22 minutes were the video because I haven't cut us into pieces because I'm just getting arrogant. But I think I could do like a whole module in one shot. But if I was using the I, I find very unforgiving and I could
07:30
end up running the video, basically,
07:33
um, and you may actually see me do that. Luckily, we're learning the eyes so it would be appropriate.
07:40
But I think, man, I was much more forgiving. But we'll start with Nano. If you're not familiar with any Lennox checks editor, I would encourage you to use Nano just because it's easier.
07:48
But if you want to be one of the cool kids, they seem to like the I.
07:53
So whatever works for you.
07:57
So I say Nana
07:59
and my file,
08:01
it'll open up my file in Nana,
08:03
which again is a text editor. So we see the two lines that we have here with Nano Weaken. Just directly start typing. If I wanted to start at the beginning, I
08:16
Hi, George again. Ha Georgia 1/3 time. And I made it caps. For whatever reason, I can
08:22
use my heir accused to move around
08:24
completed goal. Like how a text editor you would think would work.
08:28
How about green gumdrops on awhile? Sake? Green gumdrops.
08:33
I have to, like, make lists. I always do. Color is I'm not sure why.
08:39
Um and then what I could do. You can see there is some specials
08:43
commands you do down here at the bottom.
08:46
Like, um, if we do control w for where is that? Will search obviously in something this small don't really need to search for anything
08:54
but in a longer file. We might. So it search for blue sound Blue highlighted that line
09:03
And if I put in like
09:05
per bowl
09:07
purple, not found weaken Search Our files got really long configuration files for programs of devices. The search can be of the knife
09:18
to get out of it. It says control X
09:22
exit here
09:24
on save modified buffer Answering no will destroy changes. So if we say no, it will delete all our changes. If we say yes, it will save the file to say no
09:37
point in and said why
09:41
we did the same thing with the I
09:43
another editor
09:46
who ve I my file
09:48
begin It opens up. And since I didn't save the changes, I have hydrated again and hydrogen 1/3 time.
09:56
If you're always gonna be a little bit different if I just start trying to type high Georgia Well, I didn't get an age. And then when I took the I,
10:05
something interesting happened. I got
10:07
insert mode here, oddly enough, in order to insert text into
10:13
the file with the eye, you have to be an insert mode and should have command mode, which is the default
10:20
hitting the ikey is what put you an insert mode.
10:24
So
10:26
now that I'm an insert mode, I can say hi, Georgia
10:31
two and 1/2 times
10:35
And then I can get out of this to go back to command mode. I mean, as long as I'm in in shirt mode, Aiken tight, just normally
10:46
hit escape. You see that in shirt goes away
10:50
and then, you know, if I keep typing, just got rid of something.
10:54
What did I just do? The whole line just went away.
10:58
What commanded? I hit?
11:00
Well, I actually hit DDS. I hit
11:03
D Ky twice. That's just delete the whole line d D.
11:07
It's also just dump whatever.
11:09
Who d d will delete the entire lines or duty again that'll get rid of the highlighted line. Of course, I can't just start typing in, but I could do the eye again to get back into insert mode
11:22
on, and I could say, Hi Georgia mother kind
11:28
escape to get out.
11:30
They're certainly other commands besides deviated to lead a whole line. I like dee dee because often have lines that need to delete shell code that we'll see when we you exploit development.
11:41
So
11:41
no it's not so bad if you just remember what you need to be. An insert mood on escape and
11:50
don't end up hitting any strange commands by accident. When you're not an insert mode, for instance. You know I hate to these and beggar the way
11:58
and then you know that could be rather hard to recover from
12:01
also, to save things in guy. It's a little bit different, but we actually do is shift
12:07
on then Colon.
12:11
Maybe she would get the colon down here at the bottom,
12:13
and we need to do this in command mode.
12:16
Then we want to say W for right and in Queues was going to write, So it is going to save the file on that is going to quit
12:24
good dinner
12:26
that did save our changes this time
12:31
again. I mean, whatever you think is best, there are other ones as well. I mean, even some graphical ones.
12:37
But other knowing Nano r V, I
12:41
felt both. It's certainly worth. While you may find yourself with only command line access on Olynyk system on a pin test, you might need to, and it's something and being able to do it all from the command line is certainly worth knowing.
12:54
They're both work. There were commonly seen on system, so you should be fine as long as you know one. But
13:03
whichever one works for you.
Up Next