Hello, and welcome to this first demonstration,
a demonstration where we're going to dive out to the command line,
this time in an Ubuntu system, and take a look at the ls and stack
commands so we can list our permissions.
Are you ready?
Are you really ready? Then here we go.
Well, here we are, command line heaven, and welcome to my Ubuntu 20.04
system, although the reality is it shouldn't make a lot of difference which
system that we're using to do this. Now if I just go through and gain some
focus, we can go through and say ls ‑l /etc/services is a file that we can
go through and take a look at.
Now when we go through and look at this, we can see this is
a regular file. It starts with a dash.
We've got our permissions.
Don't worry too much about those at the moment, and we'll explain
the permissions as we go through. A hard link count of 1. It's
owned by root, group owned by root.
Ah, but now it's getting difficult, isn't it?
14,464 bytes, so that's the file size, which is, which is, come on,
come on tell me. Well, we can go through and take a little bit of a
sneak cheat, and we can see, well, that's 15K.
So as our file size becomes bigger, it's much more difficult to be
able to calculate it in our little minds as to what the size is, so
lh human readable can be really useful.
This file was last modified on February the 16th 2020,
and we can see then its file name.
Now if I did the same thing where we go through and do, let's say, ls ‑lh and
take a look at the TTY that we're connected to, we can always go through and
look at the TTY file by looking at the tty command.
That will tell me the TTY, the terminal that I've connected to.
So that's giving me the full path through to the file.
So as I then go through and list this, when I look at it, we can
then go through and see, well okay, it's c now for a character
device. We can see our permissions. Okay, it's only got the one
name, a hard link count of 1.
We see it's owned by the user vagrant and the group tty. But then
when we start looking at the information relating to what should be
our file size, we can see it's 136, and 0.
Well, this is then more driver information rather than the actual file size, so
be careful with special types of file. It might not be the file size that we're
seeing. And then we get into the date, so February the 10th 2022 being the last
modified date and time. And of course, every time I write to the console, I'm
modifying it. We could see something similar. If I go through and look at ls
‑lh, it's not going to help me, the h here, because of course we're not going
to see our file size. When I go through and take a look at /dev/sda1, so we're
looking at a block device here, we can see the b for block device.
We can see as we run through, the user owner is root,
the group owner is disk, and then we've got 8, 1. Again, this
is driver information that we're looking at.
I can show you that driver information more clearly if I look at the ls block
command. So we can see it's 8, 1. When I look at ls block,
let's move down to sda1, and we can see there the major
driver number of 8 and then the index on that,
the minor number, being 1.
So just be aware, we don't always see the file size. If I clear the screen,
we know that is Ctrl and L. If we want to look at a file, and let's
take a look at one of our more general file, so let's go through and
take a look at stat and then /etc/hosts.
This is the same type of information that we're able to see
with our long listing with ls, but you can see it's
organized in a slightly different way.
We also get to see information perhaps in multiple ways.
So rather than just seeing the dash for the file type,
we can see this is a regular file.
It's shown on the right‑hand side of the screen.
When we look at the ownership of the file,
we're not just looking at the username, we can see the username and the user ID.
The same with the group ID. We're not just limited
to seeing the last modified time.
We can see the access time when it was read.
We can see the change time,
that's when the metadata changed, and some file systems support a creation date.
When we look at our access permissions,
we can see it in both octal, the numeric format, as well as then going
through taking a look at it in our normal symbolic format.
So this then is a very good way to be able to get huge
information coming back about our metadata.
But also, if we need to script and extract information within a script,
this can be really useful.
So for example, before I do something to a file,
I might want to check its permissions.
So I can go through and do a stat ‑c. If I go through look at %a,
escape and dot will bring up our last arguments.
So that saves me having to type /etc/hosts all over again.
And anything that saves me typing I'm going to really enjoy. Look at this.
We're able to just extract the information that we want.
No other superfluous information.
That's perfect for operating within a script.
If I use the uppercase A, it's not so useful to work with within a script,
but I can pull out just the symbolic information.
But of course, that's symbolic information,
both the permissions, and also the file type.
So hopefully, that gives you a good idea of how you can extract metadata from your files.