Terminal Lesson 22
Hey guys, this is Macaden on with our 22nd terminal lesson. In this lesson, I'm going to be showing you how to get information about files without having to use a GUI. This is useful if you have to SSH to your Mac from another computer and you can't use other commands to get information about a file that you really need.
So, to do this, we're going to be using the mdimport
command, which stands for metadata import. What it does is it reads through a file, reads through some permissions, some attributes, stuff like that, and it gives us information about the file. You can even set how much information you want to get, and I'll get into that in a little bit.
So here on my desktop, I have three different types of files. I have a Pages file, I have an image of an Apple logo here, and I have a video file. I'll just play this; this is a ScreenFlow encoded video file. Um, yeah, so it's like a 5-second little video.
All right, so what we're going to do is we're going to get information about these from the command line. The first thing we're going to do is type mdimport -D
and then a space and then a 2 for now. Um, and we'll do testpages.pages
to get some information about this.
Don't give us a lot; you can see it's going to tell us a bunch of metadata information. It's going to tell us the type, it's going to tell us the dates and stuff, it's going to tell us the stuff like that, the fonts they're used, and then here it'll tell us at the end the text content. That's pretty cool, I think.
So this actually knows how to read a Pages file. So if you're at school or something and you need to get a Pages file from your Mac, you can mdimport
and you'll be able to see the contents. Um, so let's just see if we pipe this into more; obviously, you can read it better.
Um, anyway, let's do mdimport -D1
and see what the difference here is because I want to explain in a second what -D
really does. It will give us almost no information, and the reason for that is because -D
stands for debug level. The higher it is, the more information you're going to get. So it's one to four; four is a ton of stuff.
You're going to see, um, here let me just pipe it into a file, and you'll be able to look at the contents of this file and see all this stuff. It's really a lot; it'll tell you about all the libraries that's loading and stuff like that, and it's too much. Um, so that's why you can set the amount of information you're going to see.
And anyway, I'll just show you; I mean it's a pretty straightforward command. You can obviously look at the manual page for other things. I'll show you some information about a PNG file. Um, so let's see here; you can see the pixel width, pixels high, the pixel count total, that's just those multiplied, obviously.
Um, the orientation, that's going to be one by default, um, some scales, some information about that, some pretty cool stuff, and I'll do it once again to this movie. And, um, I'll do it to shatter.mov
, and if you take a look, you can see the resolution. If we scroll up, you'll see a bunch of information about this.
Um, the encoding application ScreenFlow actually puts itself in there. Uh, here's the display name; it'll have tons of stuff, and it's actually like the codec and stuff used. I think it's pretty useful to be able to get that.
So if we look at the man page here, I'll just take you through a brief look through. You can obviously use plugins; you can, um, do a lot of cool stuff here. You can, um, just get the file schema and exit. There's, um, you can see a bunch of different stuff. Here's the -D
, obviously, which is the debug level.
Um, and yeah, so basically that's pretty much it. mdimport
it's a pretty cool command. I've used it multiple times from school where I want to get contents of a Pages file, and it's quite useful.
So anyway, thanks for watching, kids, and subscribe, and goodbye.