EX200 Red Hat Certified System Administrator RHCSA – Linux command line Part 2
4. File and folder ownership and permissions. Commands “chown, chmod” part 1.
Welcome everybody to this tutorial. Today I will talk a bit about provisions, how you can change them, how you can read them and what they are in general. So first off, let’s just go ahead and open up a file. So don’t worry about this command that I’m going to use now. It’s called cat. I will explain it a bit later on when we go into text editing and phrasing and extracting text formatting. It in general, but for the time being, just leave it be. You’ll see soon enough what it does. It just pulls the content out of a file and then prints it out to the screen. So I have a file here, it’s called mode.
And in that file I’ve made a small demonstration of small, I wouldn’t say demonstration, but an example of syntax of how this thing actually looks like. So you pass in the command, so you pass in the command which is chmod, which is chmod and then where it says owner, Group, world and Path. Path is basically path to the file of which you wish to change permissions. Owner is changing the permissions for the owner, group is changing the permissions for the group and World is basically changing the permissions for anybody who can physically access the computer.
I will shortly explain what this actually is. So let’s go LS mode. There we go. So down below you see that the first spot signifies what is it? Is it a directory? Or is it a file? Is it a link? That I’ve already explained. Next three fields basically tell you the permissions which this user has. So what does the owner by the way, this year, this is the owner of the file. So what sort of permissions does this owner have? It has a read permission, so it can read the file. It can see the contents of the file, will be a more simpler way of putting it. It has a write permission.
So w, this is basically a permission to edit and alter it and modify the file, change it. It does not have the permission to execute the file. Although if I am the owner of the file, I can give myself the execute privileges as well. However, until I do so, I will not be able to execute it at all. I know that mode is not there is nothing to execute in it, but still, suppose there was a script here which was to be executed and unless I actually gave it execution privileges, there would be no other way I could do this. Then the next three spots signify permissions for this particular group.
So any users belonging to this group will have this set of permissions here. So again, the group can read it, can modify it, but there are no execution privileges for the group. Next up, it’s the world. And by world I don’t mean the whole globe or anything of a kind. Rather instead I am referring to all the people who can actually log into the computer. Everybody can read this file.
Everybody can view the contents of this file without any problems. So let’s just go ahead and create a new file with touch. Just type in touch like this. And how shall we name this file? Well, I don’t know. I’m running out of inspirations here. So let’s name this file Linux. Actually, no. Let’s call it Red Hat. Excellent. So we’ve created Red Hat and let’s see what are the permissions for Red Hat? Sorry. Not LS. Excellent. So we have the same set of permissions as we do with the mode.
Now let’s say we’re going to use this file in order to run our tests on it. Before we do, let’s just go up a little bit and see what basic permissions do we have? So, as I mentioned before, have read, write and execute. Those are the three basic, basic permissions that you can give to a user, actually or to a user group for a particular file. They have their numeric values, they have their see these letters here? They also signify their values. There are also representations of them. Let’s put it so however, numeric values are far better. You can use RW and X plus minus in front to quickly alter the permissions for the owner of that file. However, if you wish to conduct major changes, you can do it in this fashion. So let’s say that seven. It’s basically four plus two plus one, as stated here is read, write and execute.
Six would be two plus four, which is read, write. Five is four plus one. So read, execute, and so on and so forth. And if this doesn’t seem quite as clear as it should, don’t worry about it. A lot of people got confused here. I got confused here. But it all really sinks in rather fast. So no need to panic or anything of a kind. Let’s go ahead and clear the screen. I’m going to go ahead and cat this out and let’s say that I want to change the permissions of the file red Hat. So let’s do ll Red Hat just so that we have the overview of what they are at the moment. Now let’s type, as the upper syntax says we should. Let’s go ahead and type in the command so chmod space. And what sort of permissions shall we give it? Well, let’s first think about what sort of permissions do we want our user to have? Let’s say that we don’t want him to actually be able to change the file, but I want my owner of the file to be able to read it and execute it. Let’s go ahead and conduct such a change.
So read and execute would be four plus one. That’s five. The first argument is five. That’s what the owner of the file can do. Let’s see what now? What sort of permissions do we want to give for the group. Well, I want the group to be able to do the same thing. Actually, let’s not change anything here. We want the group to be able to read it and to execute it. And the world well, we’re not going to really change anything for the world as yeah, read is way more than sufficient for the world. So let’s just leave read as it is and give it four. So it’s chmod 55 four that I have typed in Space and then I type in the name of the file. Also notice that here it says Path. Since I am in the same directory where the file that I wish to modify is located, I could also if I wasn’t if I was elsewhere in the file system, I could type in I don’t know, I could go about things like this.
So home random Guy red Hat and this would change it for home random guy, red Hat excellent. So you see, you can compare the previous permissions to the current permissions. You see that this is immediately changed. It says that the user can read and execute. The group can read and execute. The world can only read. Suppose I want to quickly add a write to the owner of the group. I would do chmod without any calculations of whatsoever or looking at the numbers or anything of a kind. Chmod plus x. And here we’re going to need the name of the file. Red Hat let’s see what we have done. Oh, actually we haven’t done anything because it already has execute privileges. Sorry, I’m going to add write privileges. That’s what I wanted to do. Excellent. So how does this look like? Now the user can actually write, read, write and execute. So here it can read, not write and execute. And now we have changed effectively for the group as well. The group now can actually read, write and execute. And here read, write sorry, up here it’s read no writes and execute. But it’s here it’s read, write and execute. We have changed our minds. We no longer wish to give the right permissions.
Let’s say chmod minus W. What has happened? The W is gone, as you can clearly see. So these are the quick ways of changing the owner and the group to which the file that owns the file as well. Initially I just said the owner, but it’s actually the group as well in this particular example. Anyway, there are other things which we can do. Let’s just go ahead and clear the screen with this and type in chmod space help. So what do we have here? This is probably the V and R are probably the ones most important here. The one that you will mostly tend to use. So verbose output is just to tell you what it is that it is doing and recursive. Well, just read what it does, change files and directories recursively. So it just goes into the sub directories of directories, and then it goes into their sub directories, and then it finds files there, and then it does alteration on the whole string. Let me just show you. Let’s see, what do we got here first? Do we have anything of no importance? So we got mode, we got red hat. Come on. Something apparently okay. Oh, I do have a test folder.
Let’s utilize the test folder. Let’s see what it actually has to say on the subject. So what do we do? We type in oh, wait, do I have anything in the test folder? Let’s just go ahead and check. If we don’t, we just need to create. Okay. So we can go ahead and create with touch. Test one, test two, test three. Let’s go back a step. Do Chmod. I actually don’t know what they are first. So ll Test folder. Excellent. So they all have read, write, and no execute privileges. Let’s change it to execute privileges. Let’s give execute privileges. But if we print the working directory, we’re not actually in the test folder at all. Rather, instead we are outside of it. So how do we go about this? Well, just type in Chmod as you would ordinarily type in R space plus X space. And now we need a path to the file, which is basically test folder and then change everything inside of it. Excellent.
So let’s go ahead. Voila. There you go. So compare you can now compare these results to these results. It has changed everything within that folder and it has given it these provisions. But when you do it like this, you see that the world changes as well. The group changes as well, and the current user changes as well. So all the permissions are changed, which is not the best of practices. What you can do with ease to avoid this is simply type in CHR R and then use numbers as I have used them before. In that way, you can be absolutely certain what changes will take effect and what will be changed to what, who be able to do what, et cetera. Anyway, here, I’m going to call the tutorial. I’m going to bid you farewell. And I’ll hope, and I sincerely hope that I shall see you in the next one.
5. File and folder ownership and permissions. Commands “chown, chmod” part 2.
Welcome back everybody. Today I am going to go ahead and instruct you I will show you how to change the ownership of the file from one user to another or from one group to another. Anyway, I have already explained that this first part is actually the username of the user who owns the file and this is actually the name of the group that it owns the file as well to which the file belongs. Anyway, these things you will frequently need to change well not later on in this particular system we will do this in more detail, we will mention it more but there is really nothing to it. We will mention it when we get into user creation and user management but for the time being I mean the principle will remain the same. There is nothing fundamentally different that I will do with this particular command. It’s very similar to chmod. If I type in chmod, this one is simply ch owned. So who owns a particular file somewhere or a set of files here if I just show you the help menu come on at the very top you can see usage so it’s ch owned then the owner, the group and then the file. Keep in mind that this file can actually be a path to a file not doesn’t need to be necessarily the file itself rather instead it can be the path so you can change the ownership from anywhere on the system without any sort of problems of whatsoever.
Verbose is also not bad to use that can give you a bit of extra information and down here I’m sure that we have recursive Excellence and we have also recursive operating files and Directories Recursively. This is pretty much the same as in ch mod primarily because it does the same thing for every for the subfolders and the files within those folders no problem. Okay so there are some other which is very nice as well. It says change the owner and or group of each file only if it’s current owner and or group match these specific yeah it says something out there match those specified here I guess I’m missing one letter there but it doesn’t matter either may be omitted in which case a match is not required for the omitted attributes.
So this is very nice if you want to like do changes on particular things and leave other things untouched but generally what you will be using is a very simple version of the command one of the most used arguments here will of course be verbose and recursive. You can also get the version text if you want. Also one more of those general things version. And this is pretty much unique. I wouldn’t say same, but generally the same for all the programs out there running in. Linux that you can operate in terminal. Very important thing, this version, primarily because if you have a bug, if something’s not working out, you need to go out onto the net and see solutions related to your particular version and not to something else. Anyway, let’s just go ahead and see how this works. So let’s ll test. Excellent. So test is owned by random guy and by group random Guy.
I need to change to Root because the only other user that I have on the system is actually Root. So su? Well, technically not, that correct, but I have Root and I have random Guy, although I do have other user groups primarily because the system generates them as well. Anyway, let’s just go ahead and type in Ch own and I say Root and then I say file. Test one, two, three, press Enter. If I type in ll. Test one, two, three. There we go. You can see that no longer is the random guy the owner of this file, rather instead now Root is the owner of this file. But wait, we still have the group. So whatever rules apply here to the group, pretty much anybody belonging to this group will have the same permissions as the group for this particular file.
So we do need to change that as well. We need to type in Ch own. And look, now you need to type in root, then the name of your group, but first colon. And then type in the name of the group which is basically root for root space, name of the file, test one, two, three, press Enter. Simple as that. You get the result and I type in Ll. Test one, two, three. And there we go. Now I have successfully changed the ownership of a file group to the user Root and to the group root as well. Sorry, I got confused there a little bit. Anyway, this functions do the same way that the Ch mode mod does. So you can just pass in the arguments here. I’ve already showed you the R. Let’s try with the verbose thing. Excellent. So nothing has changed. Has ownership of desk one, two, three retained as root root. Okay, let’s play around with it. Let’s see what’s going to say next.
But first, let’s just clear the screen a little bit. Ch own. Now I shall show you something. So never mind. Actually we could do it like this and then we’re going to do the Ch own thing. Excellent. So here we go. Delete this and type in random guy colon random guy. Excellent. And now we want to pass in the argument verbose. So it actually tells us what it is doing. I mean, for just one file like this, sometimes it makes sense, sometimes it does, most of the time it wouldn’t. But when you have, I don’t know, like 50 files, something like that, you definitely want to have that for both output. I mean, you’re not going to skim through every single one of those lines, but they’re going to keep popping your terminal. You’re going to be looking at them and they’ll generally be exactly the same lines. If there’s an anomaly somewhere, 90% of the time there is some sort of a problem there.
So let’s say that I press this. It says change the ownership of test one to three from root user to root group to random guy and random guy. Very simple. And if I type in Ll, test one to three, press Enter. Once again, you can see that we have managed to successfully change from root root to random guy. You can have pretty much as many groups or as many users as you wish, as many as your system can physically support. And these sort of information can be seen in a file. So how many users you have, which users you have, how are they configured, how many groups do you have, et cetera. But those things are found in Etsy past.
WD and Etsy shadow. We’re not going to do that for the time being. If I showed you the files, they would mainly serve the purpose of confusion because there is a lot of stuff there aside from the user names. But I don’t want you to worry about it. We will deal with it in due time. For the time being, I just want you to know that there is a file that lists all the users and there is another one which lists all the groups without any problems of whatsoever. Anyway, I would like to be with you all. Farewell. And since you’ll hope that I shall see you in the followup tutorial.
6. Move, delete and copy files. Commands “mv, rm, cp.”
Welcome all to this tutorial today. I’m just going to first go ahead and clear the screen and afterwards we will deal with a couple of commands, three of them to be exact. So we’ll have RM, we will have Move, and we will have CP for copying. Anyway, let’s just go over them. The first first one. Well, RM is always nice, and RM is basically used to delete files, delete folders, delete pretty much anything you wish to delete. However, you should keep in mind that this is not like deleting in Windows. Once you delete them with RM, it is not very likely that you will get them back, or you could get them back, but you would need to invest a ridiculous amount of effort into actually doing it, and still it would be rather questionable. So keep that in mind when using RM, especially when passing certain arguments to it which cause it to skip verification or something of a kind. And you delete a folder full of things, but you can’t always do that. Here’s why. You can’t delete a folder full of things unless you specify, unless you pass certain arguments to the RM command. This is a precautionary measure, to say the least.
So I have test folder which has certain files in it, and if I say RM test folder, it’s going to tell me immediately, cannot remove test folder. It is a directory. Well, what seems to be the problem there? So what? I know that it’s a directory, I want to delete it. And it might seem strange to you, but you can’t just delete folders just like that, primarily because once you do, they’re gone. The good place to look is, of course, the Help page. And we are looking for the F command. F. So we, of course, as with all others, have recursiveness. And if you want your commands to be recursive to I don’t know, if they perform a certain operation on a directory or in a file or something of a kind. Recursive generally means that I’ve stated before that they do it on their subfolders and then they do it to the files within those subfolders. Whatever it is that the command does.
So lowercaser or uppercaser or recursive. I purely doubt that anybody actually uses this recursive. Usually it’s capital R. Lowercaser. These things are universal. Pretty much any command that has recursive abilities will actually have these two arguments pretty much embedded into it. Anyway, if we move upwards and there we go, we have fours here, ignore nonexistent files and arguments never prompt at all. So it will never ask you any questions. It’s just going to go through it and it’s going to remove things, clear them rather fast, which is not a very good thing. Well, it is efficient in the sense of deleting files, but it’s not a very good thing in the sense of recovery. Anyway, we will use the recursive and the force function today so in order for you to delete a directory, you would need to delete its contents. So rmrftestwoa. There you go. It is gone. Ll the test folder is no longer here. You cannot see it, you cannot find it. It is gone. Permanently gone.
Yeah, too bad. What can you really do about it? Anyway, be rather careful when using RM command, you can delete regular files with RM. Let’s see what so test one, two, three. No additional arguments are needed, but like this, it’s going to prompt you for actually prompt you, and it’s going to say, RM, remove regular empty file. Test one, two, three. Do you want to do this or not? If you do, you type in Y. If you’re not, then you type in N. So let’s say that I am, and if I do Ll again, it’s gone, completely gone. So let’s try one more thing. Let’s try to delete the file called Red Hat, and we’re going to do that by telling RM not to ask us any questions. So Red Hat. And if I say F, press enter. You see, this is just going to remove the folder. This is just going to remove the file without any problems or whatsoever. But the same applies as with the folder. It’s not going to ask us any questions, it’s not going to care.
You’ve told it not to care. And it will just go about things, deleting them, which is pretty bad. Anyway, I’m going to go ahead and clear the screen. We have two more commands to process, which is basically CP, that is copy. And here’s how it works. From and then to, you type in CP, you type in the path to the file that you wish to copy. And then you type in the path destination. So source and destination from would be the source, to would be the destination. Simple as that. Let’s just go ahead and take a look at the CP help. Oh my, there’s a lot of things here. Anyway, what are we looking for? Sure, we got verbose, but we’re not really well, we’re going to for, as I said before, for smaller amounts of files, it’s not that important. But when you got 50 or 100 or 200 or 10,000, not a bad idea to have this turned on. Well, maybe not for 10,000 because you’re not going to be able to look at them all. But let’s say for 50 or 100 or something of a kind, it’s not a bad thing.
Anyway, what are we looking for here? And there you go. You see this reoccurring subject, this reoccurring theme with recursiveness, it’s dash R, dash R. I’m just trying to make a point that other commands are also similar in terms of arguments. So if you’ve got one set of arguments that you’re passing to one command, and they have a certain marketation, they have a certain letter of the keyboard reserved for them with a dash, it is very likely that those things are general and that they are used in other places as well. So let’s just continue looking through here. Again, you have the force command. You see it’s the same. There is the same description as well, you can read through it. Forgive me if I’m mistaken here, but I am 99% point 99 sure that this is exactly the same description as well, feel free to look at it, I’m sure you won’t get disappointed there. Anyway, we got a D no, don’t care about that for the time being, archive attributes, et cetera. Anyway, the only good option here for me is the force. And you can use force with CP far more often than you should with RM, primarily because you’re not going to mess anything up.
So what, you’re just going to copy files from one place to another? They’ll still be there, they’re not gone anywhere. They can’t get legs and walk out of your system. So no problems there. Anyway, let’s just go ahead and try to copy something. What we got here? We’ve got file one. So type in let’s do this. So clear LLCP, file one. Also, what is very much applicable is home. I’m just specifying, I’m just giving an example of a path. This can be typed in so many different ways for home, but no, okay, random guy, file, file one. I would like you to copy this to the downloads folder. So go to downloads. There you go. Nothing too complex, nothing out of the scope of understanding. I would say just CP one path and then another path space and then another path. Simple as that. Press Enter and there you go. It has indeed copied it there. It remains here. But let’s go to oh, we don’t actually need to go anywhere. We can just type in Ll downloads and surely enough you can see it there. It’s the very first entry, file one, no problems. It is there. Anyway, let’s just go ahead and clear this.
There’s also another command which you can use, which is move is also a way of renaming things. So let’s say that I have file zero one. I would like to rename it to file 0001. So file actually, I would like to rename it to something better. I am here. Okay, think that should do it. And if I press Enter, there are no new paths specified. We’re only using the current working directory, which means that we have indeed renamed something. It doesn’t need to be the case. But here in this demonstration, I didn’t actually move anything, I just renamed something. I just renamed file zero one into im here, not a big deal. That’s how you change names in Linux terminal. Very nice. Unless you actually open up something and save it with another command. Anyway, where it says file one, you can have a path to anywhere in the system where you have a permission. And again, where it says I am here. You can also have a path to this file called I am Here, which can be anywhere in the system. Again, as long as you have the proper permissions, I’ll just go ahead and clear this. There we go.
We can clear the screen now. Just thinking that we actually covered them all. So what did we do today? We have RM to remove things, we have CP to copy them, and of course we have the last one, which is basically MV Move. So you can move anything from anywhere in the system to anywhere else in the system. So if I type in Move, I am here to I don’t know, we can move it to wherever we want to. I can say Downloads, and if I press Enter and ll there we go, downloads. Take a look, it is transferred here. Indeed. So if I type in ll now, you will see that it’s no longer in my current working directory. It has been moved out of there. It has been shipped away. It’s gone. No problems. If you have any difficulty understanding or something of a kind, please feel free to post me a question in the discussion section on your demi. I am there. I check them several times a day. So if you post a question, you will get an answer within a 24 hours time frame. We’ve got 99% chance for that. The rest, 1%. I suppose, I have no idea. Maybe. I can’t imagine what could happen, primarily because I do review them several times a day. And if any of these things are unclear to you, please do not hesitate. Just go into the discussions and ask away. I will answer you. I will try to help you to the best of my abilities. Anyway, just want to put that in there to remind you. And for the time being, I shall bid you all farewell and hopefully hope to see you in the next tutorial.
Interesting posts
The Growing Demand for IT Certifications in the Fintech Industry
The fintech industry is experiencing an unprecedented boom, driven by the relentless pace of technological innovation and the increasing integration of financial services with digital platforms. As the lines between finance and technology blur, the need for highly skilled professionals who can navigate both worlds is greater than ever. One of the most effective ways… Read More »
CompTIA Security+ vs. CEH: Entry-Level Cybersecurity Certifications Compared
In today’s digital world, cybersecurity is no longer just a technical concern; it’s a critical business priority. With cyber threats evolving rapidly, organizations of all sizes are seeking skilled professionals to protect their digital assets. For those looking to break into the cybersecurity field, earning a certification is a great way to validate your skills… Read More »
The Evolving Role of ITIL: What’s New in ITIL 4 Managing Professional Transition Exam?
If you’ve been in the IT service management (ITSM) world for a while, you’ve probably heard of ITIL – the framework that’s been guiding IT professionals in delivering high-quality services for decades. The Information Technology Infrastructure Library (ITIL) has evolved significantly over the years, and its latest iteration, ITIL 4, marks a substantial shift in… Read More »
SASE and Zero Trust: How New Security Architectures are Shaping Cisco’s CyberOps Certification
As cybersecurity threats become increasingly sophisticated and pervasive, traditional security models are proving inadequate for today’s complex digital environments. To address these challenges, modern security frameworks such as SASE (Secure Access Service Edge) and Zero Trust are revolutionizing how organizations protect their networks and data. Recognizing the shift towards these advanced security architectures, Cisco has… Read More »
CompTIA’s CASP+ (CAS-004) Gets Tougher: What’s New in Advanced Security Practitioner Certification?
The cybersecurity landscape is constantly evolving, and with it, the certifications that validate the expertise of security professionals must adapt to address new challenges and technologies. CompTIA’s CASP+ (CompTIA Advanced Security Practitioner) certification has long been a hallmark of advanced knowledge in cybersecurity, distinguishing those who are capable of designing, implementing, and managing enterprise-level security… Read More »
Azure DevOps Engineer Expert Certification: What’s Changed in the New AZ-400 Exam Blueprint?
The cloud landscape is evolving at a breakneck pace, and with it, the certifications that validate an IT professional’s skills. One such certification is the Microsoft Certified: DevOps Engineer Expert, which is validated through the AZ-400 exam. This exam has undergone significant changes to reflect the latest trends, tools, and methodologies in the DevOps world.… Read More »