And now we're going to move out to the command line so we can see some
of our advanced operations using symbolic notations just using some of
the things that are just not possible really when we're working with
our numeric or octal notation.
And look at this, our glorious command line. We'll start by clearing our screen,
so we've got a nice, clean work space to be able to begin.
We're going to take a look now at some of the advanced operations
that we can carry out using our symbolic notation.
And we're going to begin by creating ourselves a directory structure.
Mkdir ‑p allows us to create the parents. We're working on Ubuntu, so
why don't we have directories that represent the different Ubuntu, LTS,
or long‑term support, versions?
So we've got our upper level directory of Ubuntu, and we can
create then a range of directories below that.
So we're going to have a list in our range, so 20, 18, 16, and we
can have 14. Every two years, there's a new LTS version, and that
LTS version is due out in April, so .04.
So we can close off our range with a brace bracket and add
in 04. So this is going to create 20.04,
18.04,
16.04, etc. We can also have a list of subdirectories to create
in each one of these directories, gold for the first release and
current for the current releases.
Service packs are updated to support those OSs.
So that was very,
very easy, but look what we have created. If I go through and use
the tree command against the Ubuntu directory,
we can see then that we've created the structure
that we thought. So this is really,
really good, and I encourage you to become more familiar with
using ranges because this is just magnificent when we can go
through and create a structure like that.
We can also pretend that it took us hours to do, always a good tip.
Now, of course,
working with our default umask, when I go through and
take a look at a recursive listing,
we have the execute permission set. We're only removing two, the write
permission from others. So, we don't have to worry about setting the
execute permission just on our directories.
If I set though a more restrictive umask, and let's look at that same
operation by going through and removing the directory structure, so rm ‑r.
We'll remove the Ubuntu directory and everything within it.
Don't worry.
It's really, really easy to recreate. I can use Ctrl and R to
reverse search. And if I put in, let's say, ‑p, I know I use that
with the mkdir. I can recall then the command really easily. Having
checked it's the write command,
hit the Enter key, and we've got everything back up and running.
It's the same sort of thing with the ls command.
I can reverse search with Ctrl and R, and then go through and look
for ‑R and L, and we get our listing coming back.
Now, we can see that we have got a private structure, and execute is
not set for any of our objects other than the user.
Now, we might think then this isn't right, and we need
the execute permission being set.
Well, of course, then we can go through and set that.
That's not a problem.
We don't have to go through and recreate the whole
structure again. Before we do that though,
let's go through and just create a file.
I'm going to create a file in Ubuntu. I'm just going to call it file1. That
will do. And then again, if we check the permission for that, a file isn't
going to have execute, so ls ‑l, and we can see then file1 is just read and
write. Now why is this important?
Because if I want to use chmod, uppercase R for recursive, and then I can
use this elusive a for all objects plus uppercase X.
Where did this uppercase X come from?
Well, this is the magic permission.
It's only going to set execute if it's already set on at least one
object. So I can go through and configure it to set recursively from
Ubuntu and down. We want to make sure then that the execute permission
is set, but only where it's already set, and I don't want to forget to
add in the verbose.
I want to be able to see the permissions being set. So let me
move back and add this in, so adding in the ‑v.
And look at my excitement now! I've just exploded! We can see then,
carefully, we've set execute on all of our directories.
Moving down though to the bottom,
we can see that the file1 is retained with the
original permissions. Execute wasn't set.
We only set execute where execute is already set.
So that's the idea of the magic uppercase X, something that's just
impossible to do when using our standard octal notation.
I'm going to send my umask back to be something a little bit more
standard now. Set it to be 22, so we're removing the write
permission from the group and from others.
We can go through and create ourselves a new file. And now when I go
through and take a look at the permissions there,
we can see then hopefully everything as expected.
Now many people misunderstand the idea of +X.
If I don't specify the object, they think it means all objects.
We can see why this misunderstanding takes place.
If I go +X, often we want to do this through a script, adding
in the execute permission for the script.
It has applied to all objects.
Yes, but only because it was allowed through the umask.
If I use +X without mentioning the object, then we do actually use the umask.
If the permission is allowed through the umask, it can be set.
If it's not allowed through the umask, it won't be set.
I can show you how this works.
We can work with the same file.
We know the write permission is not allowed through the
umask to affect our group or others.
So if I go back up through my up arrow and use +w, our umask now is
applying. We can see then that the permission is retained.
It does not mean all objects.
All objects is a+w. Plus by itself means we apply
the permissions through the umask.
So now we can see using all rather than just plus, it does work as expected.
And I would suggest that you always use a if you mean all objects. Don't rely on the umask.