CompTIA Linux+ XK0-005 – Unit 04 – System Administration Part 2

  1. File System Specific Attributes

All right, now there are some other attributes that go with the file systems, and they’re specific to your file systems. Now, the extended file systems, the second and third one, support extended attributes. So does the fourth. Those attributes deal with issues about the files, such as if I have file compression, or if secure deletion is required, or if the file is undeletable, or if it’s append only. And those are things that we can add on to those files so that we can kind of deal with that, and we’re going to deal with those very specific things as we move on. Throughout this course, we’ll talk about compression and the secure deletion. So those are coming up. But it’s important to know that you can see those attributes if you use the lsattr, the LS attribute, list the files with their attributes and you can see what those are.

You can say, show me the ones with append only, show me the ones that are compressed, and you can change them with the change attribute or the chattr, but those can only be changed by the root account. So if you want to make something compressed, its attribute would be set up as compressed append and all of those other options. So those are file system specific attributes, which means that those are features that your hard drives file system can add to a file. It doesn’t mean you will always have those. If you’re using some earlier version or some other version of another file system that doesn’t support these attributes, then you don’t have them. So every file system has something I can add or take away as far as extra benefits of using the file system.

  1. Demo – Viewing and Changing ext3 File Attributes

Well, now we’re going to take a look at some of the attributes of our files. And I’m in the home directory here and live user, and we haven’t done anything special with these attributes. So if I show you the attributes of the files, got all those dashes because we haven’t done anything. So that was the list attributes command. The list attributes command also had a verbose option that let me at least see some of the version numbers, if you would, with each of those. And of specific, I’m going to look at files like the fourth sample, third sample, special, all those types of things, or maybe I’m just going to make my own. In fact, I think that might be more fun. And I’m going to change the attributes of my commands.

And so if I use the change attribute command with my help, type it to my more command, you can see that it seems pretty straightforward, right? I have some options with the commands that I can use to change the attributes, and I have some apparent attributes that wasn’t as helpful as you might have liked. And that’s where we can go to the manual, the man page for change attribute, and get a better idea of what we’re going to do. So this is going to change file attributes on our Linux file system. If you use a plus sign, that adds an attribute. If you use the minus, it causes them to be removed. And let’s take a look at what we have. We have a for append only, which is the one we’re going to use.

Compression, no dump, extended format, data journaling. So you got a lot of options. R says recursively change the attributes of directories and their content, which means all of the if it’s a directory, everything in that directory and everything below, whether or not we want to be verbose with it, or even if again, the versions, specific versions. All right, so we’re not going to do actually any of those. We’re just going to simply use our plus sign and minus sign to change the attributes to those things we saw at the very beginning, rather than worrying about more data gathering. So I’ll hit Q for the quit. We’re going to clear our screen. I’m going to use the t command. I’m going to create a file called my ext file, and I’m going to put in the stuff we typed in another file earlier.

The quick brown fox enter jumps over the lazy dog. Look at that, I typed it without one typo. That’s amazing. All right, let’s do the list attributes then of that files over all those files. And the one I just made was called the ext file. I haven’t changed the attributes. So what we’re going to do then is we’re going to actually use the change attribute command to make it an append only. So let’s do change attribute. Almost made my first typo there and we’re going to add it as an append only file. And it was the ext file. Bam. Now let’s look at those attributes. Suddenly, I’ve got a new attribute, something we hadn’t set before. So I’ve got the append only on. All right, well, now that I’ve got that, I’m going to clear my screen and we’re going to see if I can’t do some stuff to make some changes.

So what I’m going to do is I’m going to take the LS command. And remember, the LS command is going to list all my files and I’m going to redirect it to the XT file. Now, redirecting means I want the output of the LS command to go straight into that file. And when I click on that or hit Enter, it says, no, can’t do it. It’s not permitted. Now, one of the other things we have in the bash shell is a double greater than sign, which is saying basically append to that file. Boom. I hit that. And that was allowed. So let’s cat the extension, the ext file. And there you see the results of all of the LS commands being put in there. So it certainly did what we expected it to do. It allowed me to append, but not basically change the information in there. Well, let’s remove the ext file. And it says, remove the regular file, and we say, yes, go ahead and do that.

And then it tells me, hey, I can’t, because it’s not able to be deleted. All I have done with this thing is to make it append only and notice, right, who am I? I’m the root. And I still couldn’t do it. So now in order for me to do that, I’m going to actually have to change the attributes by taking away the A command on ext file, and then I can remove it, say yes, and the file is gone. So those are file attributes that are available to you. And it’s because of the different file systems that you format your drives with, which also means that these attributes exist because of the actual directory that they’re in or the file system that they’re in. It allows me to change some things, the eye compression things that we’ve talked about. And there you saw how well it enforces something like the appendix attribute.

  1. Topic C: User Environment Configuration

All right, now, we’re going to talk about these things that we call the environmental variables. And generally, we’re going to talk about variables and how you can use them, how you can change them. I kind of hinted about that when we talked about what the shell was. And the closest we got to giving you some sort of permanent storage of a value was to create a named pipe. So we’re going to talk about these user environment configurations. It’s kind of what we’ve called it. And we’re going to deal a lot with the variables, the environmental variables, variables you create, and just understanding what they are and how you can use those.

  1. Variables

All right, as you’re working with variables, we’re going to have two types of variables that you’re going to see right away. We’re going to call some of them the shell variables and some of them the environmental variables. The difference is that if you create a variable while in a shell, the variable’s lifetime is just as long as that shell is open. In fact, if you have two shells open, the variables in one shell will will be unavailable to the other shell. In other words, their scope is also limited to the shell. So their scope in their lifetime is as long as that shell is open. Close it down, those variables are gone. Environmental variables are variables that are there in the system itself, regardless of which shells you have open or what you’re doing.

Now, there are many examples of some of these variables, and I don’t want to list through all of them because there are a bunch. If you just type the set command, you would start to see how many variables there are. In fact, it would just be page after page almost. So examples might be a variable that says this is the location of where the board and shell is going to be or the Bash variable. This is the path of home directories stored as a home variable, the path for the mail under the mail variable. If you’re searching for files, we can have a path variable that says if this is the name of a file and that’s all they provide, they didn’t actually provide the absolute path to this executable.

Then we’ll look under all of these paths that you have in the path variable to see if in those directories in those paths if that executable exists. And so it’s kind of a nice thing to help you out. Even the way that your user prompt appears is stored as a variable, the prompt being all that cool stuff before you get to the part where you start typing so often. If you see your username at the host name, that’s the actual prompt that you see that has nothing to do with anything other than to help, you know, how you’re logged on and which machine you’re logged on. And you can change how that appears to you by the way it’s programmed. And then your variable.

  1. Viewing Variables, Custom Variables

Now, as I said, if you wanted to view these, you could use the set command, and the set would show you all of the variables and potentially could be a ton of different variables. Environmental variables are often found by the EMV command, so you can see the environmental variables. And if at any point you don’t want to see all of the variables, but you want to know what’s actually stored in that variable, that’s where we use the echo command. So you would say echo and remember, variables are preceded by a dollar sign so echo dollar sign the name of the variable and it would spit out on your screen the value that’s in there. So some of the things you can do, of course, is to say Set. Just type in set. You see all the variables, keep hitting the space bar, go through all the pages, go eat lunch while you’re there.

It might take you a while. I’m just kidding, it’s not that bad. You can pipe your command Set into another command with like, for instance, a Grep command. So remember, you’re taking the output of Set and you’re using that output is the input for a Grep command. The Grep command is the general or the global regular expressions and that allows you to filter the output so you could say Set pipe grep the name of the variable so that it filters for only that variable out of all of that output. Makes it a lot easier. Now, if you want to change a value, this is where it’s confusing, because many of you might be coming from environments where you do some set of programming or configurations, let’s say on like routers or firewalls or switches.

And some of the older model Ciscos, some of the older net screens, some of the other types of devices that are very popular use what we call a set terminology, meaning if you want to change a configuration, you say, set this thing to this value, and that’s how you make the change. Now we’re telling you, set is a way of viewing and not changing. And that’s true. And so that could be confusing for some of you. Or if it wasn’t confusing, maybe I just helped make it confusing for some of you. The change of value. You do not use the Set command, even though that’s what it sounds like. You use simply the name of the variable equals and the new value. Now remember, if you’re changing an existing environmental variable environmental variables are seen all over the place.

If you create a new variable by simply just saying my VAR, whatever you want to call it equals Linux is cool, then there you go you’ve just set a variable equal to this phrase now, remember, when you use phrases that have a space in them you have to put quotes around it to make it work. All right? So that created a variable. Now there’s something you need to know about making these types of changes. Variables that you create on the fly again are scoped to the shell that you’re in it’s lifetime is as long as that shell is open. Once you close it, the variable is gone. If you leave it open forever, no other shells can see it. You have to export any variable that you want to make permanent and available everywhere else.

  1. Custom Variables

All right, so how do you go through this? You set the variable. Now, this is great for your own custom variables that you might even use in your own type of scripting programs or languages. So you use the command, which is simply to create the name of a variable, whatever you want to call it, equals, and then you tell us what is equal. If you want to view it and make sure it looks right, use the echo dollar sign and the name of your variable. And if you’re you want it to be permanent, then you export it. Now, if you want, you can use the export command at the same time that you create the variable and define its value. So you could say export myVar equals, and then whatever it equals. Or if you’ve already created the variable and you just want to export it now, you can just say, export my VAR, you get the same result. So I’m just letting you know that you can export it as you create it or create it somewhere else. Export it later.

  1. Changing the Prompt

Now, for whatever reason, people get really excited about changing the prompt. Okay, the prompt is set up right now that says that you’re going to have your username at your hostname, or I should say, I’m sorry, colon the current directory that you’re in. And then after that, you have the dollar sign, you type your stuff. If you want to change that, you can, you know, right now it’s basically set up with as the prompt variable being a u, which represents the username of the current user, h to represent the host name, uppercase w for the current working directory. Those are the existing placeholders. If you want to change that, you can by changing the value of the PS one value to say whatever you wanted to say. If you wanted to say uber geek, then you can make it say that.

  1. Prompt

A prompt is just that. It’s a prompt. It has no meaning to anybody but the person who can see it. The reason that it’s set up as username and hostname and current directory is because it makes the prompt useful. It doesn’t have to be pretty, it doesn’t have to be funny. Useful is a good thing. Who am I? What system am I logged into? Especially helpful when remotely connected? And what directory am I in so I know where I want to navigate to get to some other location. I think all of that is very valuable information. But a lot of people, once they learn they can change the prompt, they have all sorts of fun. So if that’s what you want, you can do it’s.

  1. Demo – Working with Shell and Environment Variables

Well, we’re going to take a look at our shell and environmental variables and just kind of get an idea about what’s out there, what’s been defined. So we’re going to start off by just looking at the set command, piping it into the more command because we want to be able to look at it page by page and look at this all sorts of variables that have already been assigned, at least one. Anyway. Here’s Bash. Bash gives us the path to be able to get there version info of Bash the colors where you can go to get the different directory colors. Which is nice because that means hey, I can go edit some of these things, how many columns I’m going to have, the type of desktop sessions that I’m using, and I can hit the space bar and I can just keep on going through all of these little lists of environmental variables or actually of just variables themselves.

The next thing I’m going to do is look at the variables that are going to kind of be more of the environmental and I’m going to use the env, piping it into more. And now that I do that I have things like host name. So okay, notice all uppercase always case sensitive when we’re dealing with Linux. And generally you’ll see all commands in lower case and all variables in upper case. The purpose for that is if you ever had to read a script or ever had to read anything dealing with Linux, that stark contrast makes it very easy to see variables over commands. And because you always use all capital letters, you’re doubtfully going to make a mistake of having this staircase type of stuff where it’s uppercase, lowercase, uppercase. And when there’s a need for a space you can see that they use the underscore character. So that’s just typically what we see.

All right, so that was my little side note to you, little note to self when making your scripts to try to follow that convention. Okay, so I’m going to hit Q here for quit. So you get an idea of those variables and I’m going to clear this stuff off my screen. We’re going to do an echo and we’re going to echo hostname. And look what I did to hostname. I made it all lowercase, proving my point that there is no variable called hostname unless it is all capitalized. And then there’s my hostname environmental variable. All right, I’m going to make a new one. We’re going to call it my bar nicely enough, I’m going to leave it all capitalized and I’m going to make it my first name. So I think I’m safe here to use capital’s upper and lower case because that’s the value of my variable, not the name of my variable.

And so now I’ve got a variable defined, which means that I can reuse that variable while I’m in this particular shell. So I’m going to echo it echo my bar and there’s my name. Now let’s go take a look at another terminal connection. Here I am logged into this terminal as a live user. I’ll do the su to get into being the root just like am on the other one. And I’m going to do echo dollar sign my VAR and there’s nothing here. So again, kind of pointing out the fact that these variables that I defined, at least this one is only good for the shell, the scope. Let’s close that out. The scope of the shell that I’m using at this particular point. All right, we’re going to take a look at the path variable. Now, the path I said it was important to us when we’re looking at paths to different programs, program libraries and other types of things.

So if I type LS that I actually don’t have to be in the bin folder to be able to use it. The path is going to search through these different paths that you see listed and it’s going to look for my program LS. So that makes life very easy. We have a very similar type of thing in your Windows environment as well. Now, if I wanted to, I could add to the path statement. I could say that’s put in as part of the path. Now I’m going to use the existing variable path. I’m not going to change the value completely. I’m just going to add to what’s in the path statement. So that’s what the dollar sign path means. It means use the existing variable and then add to it colon right, another path. So this should go at the very end of the live user bin. I’m going to put in home slash and live user as part of that, end the quote and hit Enter.

Now let’s echo the path. And now you can see that where it ended here before I got the colon and my new add on to that variable. So I can change some of these as well. Now PS one equals let’s do command me again. Remember, this is a value so I can use upper lowercase on the value. Hit Enter and notice what happened to my prompt. It no longer is root at the local host at all of that sort of stuff. What you see happening there is that I changed my command prompt. So maybe that’s a nicer one. Command me. That looks good. All right, so that’s just some ideas of things that you can do when working with these variables both in your shell and the environmental ones, and how you can obviously have created scripts where you might have used these environmental variables within the script to do some other type of manipulation.

img