Time
6 hours 20 minutes
Difficulty
Beginner
CEU/CPE
3

Video Description

Creating Files and Directories in Linux This lesson covers creating files and directories, how to move things around and how to do tasks via the command line. Some of the commands covered are: - The touch command - The cat command - The Chmud command - The rm command

Video Transcription

00:04
Welcome to Cyberia. T. I'm Greg Stewart on your subject matter expert for Lennox. Plus.
00:09
So this is module three, part three, creating files and directories. This is a great module. This is Ah, there's a lot of good information that's in this module. Salud. Without further ado, let's get into it. Let's start creating files and understand how to create directories. Also,
00:24
we're gonna touch a little bit how to move things around to wave, have touched on it a little bit before. But we're gonna go a little on death on it in this module.
00:32
So again, I'm at my
00:33
be my work station box. I'm gonna blow it up,
00:36
okay? And I'm going to clear
00:40
is me clear screen. All right, So what's a quipped way that we can create a text file? We're talking about strictly using the command line. Right? Because I know that if I
00:51
go to my desktop, I right click Aiken, do a new document.
00:55
New empty document. Done. Documents been created. That's pretty simple.
01:00
But the reason we're using the command line again is because if we as systems administrators need to remotely log into somebody's machine and don't have any Cooley access. We're gonna be using SS H to determine a window.
01:11
So in order to you know, in that case, we're gonna be wanting to know how to do things. Be the command line. Don't stress it
01:18
so much in this class that, if anything, I want you to come away from this course.
01:23
Don't necessarily care so much about you being, you know, passing the test on the first shot or scoring super high.
01:29
Come away from this course, having a better understanding of the command, why it's so important. And I t. As a whole
01:34
you use command line so much in Mac OS X devices or UNIX or
01:41
Lennox devices even, you know, take some time and study some of the command line stuff for Windows. There's a few similarities things air named differently and displayed little bit differently about becoming an expert at the command line can really propel your career beyond systems administrator. You could become seniors too sad man, a system engineer
02:00
and eventually an architect. So there's a lot that you can do with the command line, and feeling comfortable and confident with it, especially around clients, is great because you build confidence. They build their confidence in us, A systems administrator, and they'll come to you. And
02:14
I feel like you're the subject matter expert. And that's the idea of what we want to do with this course. So please learn the command line, get good at it.
02:21
The beautiful thing about it is these linens boxes air free. You can download in stone wherever you want and then just play with all day long. So
02:30
command lines agreed. Tool. So we're gonna create files and directories using the command line. Let's start off by creating a file to show you
02:38
I'm gonna demonstrate two different ways that you can create a file. Okay.
02:43
First way.
02:45
Well, just actually create the file
02:46
as a container, Okay? It's going to create a file, and it's gonna give it a name. And that command is actually called me. Touch Command is touch, So I'm gonna touch.
02:58
I'm actually in the log, Director Emily, back out. I'm gonna go back to my home.
03:04
Okay? If I do a CD with a little squiggly right there and drops it back in my home, so do P W d in a root,
03:10
or I can go to my
03:13
CD home Sy Berry admin
03:16
and Pierre the D. M. Back in my home directory and was staying in my home directory to do these,
03:22
do these things. I'm gonna move between my home directory and actually the desktop under my home directory just so you can get an idea of how things move around.
03:29
So if I do in touch
03:32
and let's call the file,
03:36
what can we call it? Fellas? Just call a test for now.
03:39
Done. Okay, so that document test it exists now. So let's see where that where it is gonna do in L s.
03:46
And you could see that Barry's right there. Test. Okay, I can craze much. Don't want touch test too.
03:53
Doing less. And there's a document again here. Test too. Right.
04:00
Um, if I don't like, uh, you know, if I don't like the name that you could name whatever I'm just using test is as a test is an example. You can create whatever doctor you want. If you want to do a test, huh?
04:12
To see for all
04:17
fantasy football tracker.
04:24
All right.
04:27
I'm sorry I wrote that. I did the wrong Santa wrong command. So that you touch
04:31
Fantasy football
04:34
truck
04:38
on list. And there is France football tracker. Okay.
04:42
And so that's That's the touch command. That's a way of doing it. Now, what I would do if I If I want to edit that, we're gonna get into filing And in the next part of this module,
04:53
well, you could do the eye fantasy football into ah,
04:56
auto complete biting the tab key and drops you into the V I editor. Now there's nothing in this file currently because you have it. It's just a blank, empty file. It's a container
05:05
liken type. By hitting the I commit, I button lower case, I puts me in the importance of input mode.
05:14
My draft order will be
05:17
on. Do you know what Gronkowski is? My tight end. That's me. My first draft pick this year. I picked Adrian Peterson. It was huge mistaking that missing the entire season with litigation.
05:30
Um, maybe I want to have manning if he makes it back
05:34
on. Then I wanna draft you always look for drafting a good defense, so I'm gonna pick Seattle
05:41
s. So that's gonna build my draft order. It doesn't matter of adult what you put the dog community, Doc, Man, I'm gonna hit the escape key
05:47
That takes me out of editing mode. And then they hit Ah, Coghlan. Coghlan kills the session of editing and now it's gonna ask me. It gives me a chance. Prompt me what I want to do for this point.
05:58
I could do it. Quit If I just do quit,
06:00
it's actually just going to quit and not save anything I wanna do, Right, Quit or a W. Q.
06:05
That's going to save the changes to that file.
06:10
So now that I actually have something written in my fantasy, football owners were tracker file I can use the cat man
06:17
shows me the output of what's in my file, right?
06:21
Shows me that my draft early on, Cassie Manning and in Seattle Okay,
06:26
do that with any You can do that thing any of the files that you created. Using a touch command touches a great tool, especially if you just want to test and test permissions. Kay.
06:34
So,
06:35
um, now that we've done that,
06:39
let's do it. Let's use another command, OK? The other command
06:43
theater command is going to be
06:47
the cat command, actually itself okay, with the cat command. We can use CAT to actually create the file. And Ben add text in the file
06:58
on same command with with an actual arguments, the greater that arguments listed cat.
07:04
Okay. And then we'll do a greater van
07:10
and let's let's create another one. Just to a sample.
07:14
Probably. We have sampled on Texans who stands to sample
07:19
while
07:24
don't text.
07:27
Okay. What? That stuff is automatically he's dropped me into this
07:30
kind of ah, pseudo file editor. Right? So you can see my cursor there is flashing. It's Give me a chance to input anything. I want to do it. So now anything I type is gonna go into this file. Okay? So I'm gonna type. This is a test file.
07:46
And I love how this
07:49
command
07:53
makes it so easy.
07:56
Actually, just
08:00
create a file and
08:05
I love you.
08:09
Okay. When it hit, enter that. I'm gonna get control. D and I'm out and I've saved control. D is going to save it, kill the editing and save the file. Okay,
08:20
so now sample file. Where is that show up? Or did it right in getting places to in l s
08:24
Okay. And there it is right there. Sample filed out text. Okay.
08:30
Now, if I won't actually see the output of that file again, I could use the same command cat and then just sample file.
08:37
And there you see, There it is. The test file. Love Ellis. Commanding makes so easy to actually create a final edit all of the books.
08:45
So that's you can do this with this. This command his cat command
08:48
to create files. And you can also do the touch command. Great way to quickly just create a text file,
08:54
get knocked out and have it ready to go so you can take notes or do whatever you need to do. This is just a quick way of creating files.
09:01
We've seen how you can create a just a simple text file by going to the document, but going to the desktop and creating it
09:07
and you got to go now. We talked a little bit about moving things around. If I want to move this file
09:13
from, you know, Stan, wanna move sample file
09:18
context and I want to move it to the route.
09:22
I'm sorry.
09:24
The same woman move into roots. Don't do this. And
09:28
it's actually for class.
09:30
Okay, so let me go to root.
09:31
Actually, I was gonna list through, so if I do l s route
09:35
their sample filed out texts.
09:37
Okay, well, what if I want to have a copying each in each directory? I can do that to raising the CPQ man from a C P. Sample file.
09:46
Actually, now, I can't do it in here anymore in this direction because I moved it to the
09:52
route direct. So I'm gonna go see these root, and I'm gonna do a move
09:56
sample file out of complete
09:58
two
10:01
homework.
10:01
Cy Berry and Men
10:05
and Bank. Put it there.
10:07
Okay, now that it's there, I could have done it. Either way, I'm gonna go back into that, So I'm gonna go toc home cyber ery and men.
10:18
I'm there.
10:18
Yeah. Copy. This time, a copy. The file sample file.
10:22
And I'm also you can do multiple possible copy test and test two. And I'm just sitting these two
10:30
the IV route. I've just made a copy of those three files in one command and move those copies over to the Russo. Let's do it l s of at and there you can see all my files, sample file a text test and test too.
10:41
Great tool to move things around. Could command to move things around copy items.
10:46
And that's a great way to actually go ahead and do that. Okay.
10:52
Okay, so we've done that. We know how to create a file.
10:54
We know how to move a file around.
10:56
What about the permissions on the file? Okay. How do you know Who can read and write execute who owns it
11:05
and how you have how that even is displayed in lyrics slightly. It'll be easier and windows because you could go the graphical interface, and you can see
11:13
that it has be in all the different you go to security tab. You could see used the owner of the file and everything reach out, contact that owner. You know, it's it's a little bit different window. So in this situation, I'm going to say that is actually slightly more difficult and complicated
11:31
in a linen file system trying to understand
11:33
the directory, trying not the director, but the permission of a file is slightly more difficult than it is on windows.
11:41
So let's take a look at what Thea almost killed this.
11:46
Let's take a look at what the actual permissions look like in a lyrics file. And for for this example, we're gonna use our sample filed out text.
11:54
So I want to do in L s
11:58
Bash Fell, which is going to show list me of the permissions off a file that I'm going to specify.
12:05
Sample dot text.
12:07
Huh?
12:09
What you're seeing here is what it's telling me right now it's telling me that it's
12:13
read right.
12:15
You're r w free right are
12:18
couple dashes are and a one. But what does that really tell me? I mean, looking at that, that doesn't really give you
12:26
and he doesn't give you a lot. Really? So let's let's let's break down. What? Each of those
12:31
What each of those items actually mean. Okay, so
12:37
starting off,
12:37
you know, with the permissions in the command line
12:41
Well, you know what? You're looking at us. The user rights and permissions First character
12:46
starts with. If you look at, it starts with a dash. Okay. The dash, This is ah, special permissions. Flag this Berries.
12:54
The falling set of three characters are the r w in our arses are W than a dash. Okay,
13:03
is for the owner permissions. So it's basically broken up in three. Second set of three is for group permissions, and 1/3 set of three is for all user permissions. Okay, so you can see there are down here. Let's clear this so we can bring up top.
13:20
That was due that same command again.
13:24
So we have
13:24
123123123 Okay, so this 1st 1 here
13:30
it varies. Okay,
13:31
then the rest of them going, going forward are permissions. So first
13:37
is going to be the owners permissions which I'm the creator. I'm the owner of this. I have rewriting permissions, read and write permissions.
13:45
The 2nd 3 set of three characters is for the group commissions.
13:50
Currently, any groups that have access to this can only read It's really for them.
13:54
And the third set of three is going to actually be all the rest of the user group permissions.
14:00
And so what we're doing is trying to figure out how to create the permissions for this so it's a little bit easier. Okay,
14:07
So
14:09
the permission groups used Are you for owner
14:11
G for Group
14:13
O R. A for all users. Okay.
14:18
And so what we want to do is the r stands for Reed, the W stand for right in the X stands for execute.
14:26
So in our file here, it means that the owner has read and write. The group only has read and all users have read.
14:33
Okay,
14:35
so what if I don't want
14:37
once I'm the only one that I'm alone. I'm the only one that wants to be able to have access for reading, right? Or any permission for that? For aspect to this file,
14:46
I can use a command which is generally pronounces Jamaat. What it is is actually changing,
14:54
changing, changing them or modifying Jamaat. Okay, I'm gonna change. The permissions
14:58
I'm doing is changing the ownership permissions on this A mammoth, honest admission. But the file permissions on this specific file Okay, so you want to actually type the command
15:13
mog
15:13
okay.
15:15
And then
15:16
if you look at, let's back up for a second, because we have to figure out how this is just calculated.
15:24
So for every are
15:26
I'm gonna pull up a text file for this will be easy for you to understand. If I write it out
15:33
you get back to my desktop
15:43
and student. This untitled document here,
15:48
Okay.
15:50
Trying to stay away from slides don't actually have slides for this. So I want to make it so you don't have to have your power point by death or anything. So let's look at the three ownership stuff. So, for an arm,
16:03
actually, it's a little case Are
16:06
that actually equals four?
16:10
Hey, w
16:12
equals two
16:15
and an ex
16:18
equals one.
16:19
So what you're doing is you're gonna add the numbers together to get the number representing the permissions you wish to say.
16:26
We'll need to include all the binary permissions for each of the three permission groups you got. Including all three permission groups. Okay,
16:33
Sonar example. We had a dash,
16:37
and then we had an r w
16:40
dash are bash, dash and our bash dash, and it stays in. This stays in this format. Read, right. Execute, Read. Right. Execute, read. Right. Execute. You see it like this pretty much every time. It doesn't change.
16:52
So first to send a filed with Recep file permissions to read, rewrite, execute, read You have to change our ahmad Filed 277 44 file for a while.
17:07
So let's say we want to
17:10
on Lee have Let's just say we want to blow up quite open. We want everybody to have full access for you. Don't execute for everything.
17:17
What do you think the answer would be for our command? For tomato man, We're just going to pretend like this. Is that right of command Prompt here, ma,
17:25
um and then you're going to want to type in the
17:29
great the file. Okay, So to go back to our
17:34
guy here
17:37
must take him out of full screen so we could see both the text file and are
17:44
So let's do, uh, ma,
17:47
and I'll stand and let's change it. So what do we need to do if we want to make everybody you So you have to do is you have to add up these numbers
17:52
to create the image of that we want to use for each of the permission times.
17:57
Right. So we're gonna type in what we need is ah,
18:00
blank.
18:02
And you need something for
18:04
each
18:06
123
18:07
303.
18:10
Right.
18:11
We need to be able to know each of these What they're going to be what they add up to right, because right now it adds up to what?
18:18
What we're currently looking at for our permissions and the numerical presentation is ours. Force. That's four
18:26
and the double used to. So it's a six. So we're looking at a six.
18:32
I'm sorry about six and a
18:37
two and a too. Right.
18:40
So this 1st 1 this is our owner permissions on second represents two. This is our
18:47
I'm sorry I wrote this role.
18:49
Let's back out. This is going to be a
18:52
read and write, which is a six
18:56
read which is a four and read, which is a four.
19:00
So this is gonna be 644
19:02
The owner,
19:03
right? These 1st 3
19:07
sections
19:08
is going to be reading, right? So that's six vehicles up to six here. In our little calculation,
19:14
this next set equals 24 There's only one car and then following said is also for so for
19:19
group Russians and for all users permission. They both only have read access. So it's a 644 I want to change the change at lunch monitors Something where everybody can do everything. Read, write an excuse. What would that be?
19:32
Take a second. Think about it.
19:34
Grabbed. Bring the water.
19:38
So
19:42
hopefully you've figured it out. It's fairly simple. You're gonna make it just 777
19:47
Why? 777?
19:48
Because, Reid, right, execute equal to seven. And for the owners, the owners,
19:53
the group and all other users, they all are gonna have rewriting. Excuse with 777 Let's give it a shot and see the changes at all.
20:02
So back in my command, do 777 and sample filed up. Text enter
20:08
and now is doing l s minus l sample
20:11
filed a text.
20:15
And what does it look like?
20:17
It is different now. You can see that the command line is now.
20:22
I'm sorry. Not the command line. The permission set.
20:26
What is it now? The commission set. Now it looks like this.
20:32
You still see we have a first variable there. That changes. But then we had better be ex part of the pack. Start of you are the big tax. Okay, so now everybody
20:42
that kid's had see this file in their system has full access to rewrite and execute.
20:48
So these air file commissions and changes for everything you can change to whatever you want to be?
20:52
Let's try a different one changes so that
20:55
only the owner has read. Right? Next. Cute. We're gonna change to the seven everybody else on Lee has read. Only has ah
21:03
read right.
21:04
We did that one. That's 644 So let's do read. And everybody else has just read. Right?
21:10
So 12766 and sample files on text.
21:15
And you're Ellis my spell sample
21:19
next, and you see that has changed. Now reads our daily X r w dash r w dash hope they understanding this this point time is slightly confusing. And it could get extra confusing if I type a. This is where it gets a little crazy. If I type in L s Dash L A
21:41
is gonna tell me all the permissions of every file in that directory.
21:45
Okay,
21:45
You can see here
21:48
all the different ones. Let me expand this little bit sitting. See back. There we go.
21:52
Okay.
21:53
You can see that each one has its own
21:56
right.
21:57
And what do you think? The ones with the d. R. In front of it,
22:02
you can actually change the permissions on directories. Okay.
22:06
So you can see here the directory of route the owner has rewrite. Execute the group's only have read right?
22:14
I only have read and execute and all the permissions will read and execute all of the group. Other members groups.
22:19
So then it's difference of cyber answer my history.
22:23
I am. You can see here just a seven.
22:26
So you can see here is just seven and there's no others, right? So I only have or six I'm sorry. I only have read right access to my history, my shell history,
22:36
these directories of the D in front of it. It changes, right? So
22:40
you can see now. And I hope I've broken it down easy enough for you to understand what it's like, how it's broken down, permission wise.
22:47
So now you know how to change permissions.
22:49
You know how to create a file and changed the permissions on that file both extremely important things to understand. This is a ministry Er OK, so that special commissions flag we talked about can be any of the following things. It could be a D for directory
23:03
J
23:03
no
23:04
D for directory. Lower case.
23:07
It could be an l.
23:10
The filer directories is symbolically, it could be an s.
23:14
This is going to be the set. You a year set G I t permissions. This is for those things, and a T indicates it's sticky bit permissions. This this is not this set is not displayed in the special permissions. Part of the permissions display was represented as a team. The execute cute of abortion, of all the user permissions.
23:32
So
23:33
these things, the most common ones, you're going to see your just d or just a straight up dash
23:37
for us. Just a file, Okay?
23:41
And you can see that my files
23:42
are there. Other areas are just with a dash. Was the most common ones you're gonna deal with and you're gonna see on a regular basis. So now you know how to create files. Let's talk about directories.
23:56
Directories are pretty much just as simple as
24:02
as files. Okay, so what we're gonna do for,
24:06
um, we're gonna do for directories is we want to make a directory. We can do that. We can do whatever he wants. The beautiful thing of
24:14
Lennox. Right.
24:15
So let's go, Thio. Possible to go when we can do our own maker. The command is going to be maker.
24:23
Okay,
24:26
so let's go back to work mail. I'm gonna clear this out again. A clear man.
24:30
And within my home directory, I'm gonna do a maker, and I'm gonna call it scripts.
24:37
Okay? This is a common directory to wanna have. You can put all of your own scripts that you write in the script, Fuller than you could call it up when you're on your scripts. So let's do it. L s.
24:48
And you can see now that I have a directory named scripts, you can see the difference. And why should done really? Is done it with a capsule x er
24:59
So our end urges to remove scripts. And what we didn't cover Rosa was the are in
25:08
are in command, just removes. Okay,
25:12
so I'm gonna show you something. A very powerful command here in a second That will blow your mind.
25:18
It could be very dangerous if you do it in the wrong directory, but we'll get to that in a second. Let me jump back a second to go back to the file Curry creation.
25:26
We create files by doing that. You know, we thought about touching the cat command by doing our m, it removes the file together. It will delete it. Okay, so it's a good command you can use
25:37
so
25:38
back to directory. So student makers just in Cady are, and let's do it. Scripts. And generally directories are capitalized.
25:49
Just the first letter, and you can see the difference in directories. And it's actually bloom. Stabbed just white. White is just files. Just text text file stuff.
25:59
Okay,
26:00
So good stuff. Now you know how to make a directory. It's easy,
26:03
um, to remove a directory. Just Azizi. And, like, we just did remove rnd I our scripts.
26:10
Okay, now it's gone.
26:11
I'm just gonna go back and dio
26:15
maker and back scripts. Okay,
26:19
so now we have a directory called scripts. So what's
26:25
Let's go into that director, You're gonna see the into scripts
26:30
now again. So to CTU have to change the director again. A scripts, text, scripts, takes you there. We'll do l s
26:40
nothing. Right. But what do L s s a
26:42
shows. May have did and did it. Those are my directory. Navigational points. So we doing? L s minus l. A
26:51
shows me those Those two points where it takes me. Okay.
26:55
Did it will take me back one level
26:57
and just a day it will take you back to route. Okay, So you changed drugs you can do that. Sells you the permissions for it.
27:03
So that would create our director. Let's put some files in there, OK? And I'm actually what I'm gonna do is just gonna go back,
27:12
and I'm going to move
27:15
test too.
27:17
And sample
27:19
file, and I'm gonna move those. Let's copy them, Actually do C p test
27:26
too, Because whenever we remove test, and I'm going to do a
27:30
and then copy sample file
27:33
And do you fancy football?
27:37
Yeah. And copy those over to
27:45
scripts,
27:48
um,
27:51
scripts.
27:52
And I'm gonna do
27:53
go into scripts.
27:56
Oh, sorry.
28:00
Okay, Now, I have some files in my newly created directory,
28:04
which is a good thing You don't want bling directors floating around. Okay, so I've got files in there.
28:11
Let's say I'm
28:12
I'm done with this. I don't want any of the files that are left
28:17
inside,
28:18
you know, or let's say I want to actually change ownership
28:22
of every file. It's in here ownership, but I want to do a tomato, and I want to change the permissions, all the files all together instead of doing them one by one. They can get timing kind of TVs, especially in have. If you have a directory
28:36
with 50 or 60 files in it, you don't wanna go one by one and do it, you mod and change change the permissions on all those. So what you can do is you can actually just change
28:44
the permissions on every file inside the directory by going at the directory level where the files exist. So I have to be in the scripts. But see, here's, um, at home cyber admin scripts
28:55
and I could do a clod.
28:57
Some some seven dash are
29:00
J. ROC's
29:06
Go back one. Sorry,
29:07
Mom
29:11
scripts that far.
29:12
And what that does is it takes that Scripts directory and Dash R's recursive, which means it takes everything under the scripts directory and turns. It changed the commissions on 777 which is read right, execute every user on the system. Okay, so now let's do a
29:27
Let me go back into the script directory. I'm gonna go back to change directory to the scripts
29:34
unless they can see that they're all agree And the turn all green like that, almost as if they're excusable when they have full on
29:42
all permission said 777
29:45
So if I go to L S h L A,
29:48
you can see all my commands. One of them being a directory is now. Also, my directory is going to be
29:56
right. My directory is going to be have the same permissions that I gave him a sedative. Recursive. Okay, I changed the permissions on the scripts directory and everything underneath it with a dash capital R
30:07
switch for our argument for recursive
30:10
so powerful things you can do with the command line when it comes to directors and fouls. So now we have it, We know how to make a directory, we know how to remove a directory. And I changed the permissions of a directory and file commissions.
30:22
Then the next thing to do
30:23
is to actually go ahead and get into file editing, which we're gonna get into in the next section.
30:30
So hope you enjoyed that tutorial on the file editing. It's really good stuff. If you get good at this, you could get really fast. And it's a very carful tool have. Like I said again. So dig in, get your Like I said, if you haven't had it up yet get your own destro up and start playing around this stuff. Get hands on experience.
30:48
Thanks for watching. And, uh, stay tuned for the next one.

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