CompTIA Linux+ XK0-005 Topic: Unit 03 – File and Directory Management Part 1
December 20, 2022

21. File Info with ls –l

If I use the LS command with the LF option, I’m basically asking for file information and long detail information, and it’ll show me a lot of stuff. What you’ll see are several columns. The first set of columns would be basically my permissions. Now, we haven’t talked about permissions, but we will, whether it’s read, write, or read only, and what my options are. And you’ll see that our permissions are grouped together by users, groups, and special types of options.

We’ll also see the number of links that point to it. You’re going to see the names of the owner and the group owner of that file, how many bytes it is, the date and time that it was created, the name of the file, and the actual type of file will also be represented for us. And then you’ll see that that goes for files, for directories, whether it’s a SIM link or even remember we talked about named pipes as well. We can see that type of information. And the way we can tell that is that the very first column actually tells me if it’s a directory, a Simulink, a named pipe, or a file. So I’ve got the type of file, the permissions, the number of links, the owner, the group (primarygroup) that has ownership, the size, the date and time, and the type of file, all of which are available to me with the LF option on LS.

22. More File Information Commands

As I said, the File Information command will also be able to help me with that information. You type in the command file, tell me the name of the file, and it will give me the information that I need to know about that particular file, especially the type of file it is. The stat command allowed me, again, if I used it with the name of the file, to get information about it, the Mace information, and the test command. Now, the test command, remember, was designed to tell you what type of file it was and to test it against different types. It’s kind of a comparison. And one of the things you have to remember is that if you issue the test command, you often need to have the echo option selected so it will spit out onto the screen what that file was. The answer to the question that you have is to store it programmatically as an internal variable.

23. Demo – Examining File Types

All right, we’re going to take a look at these different types of files. Now, I’ve been doing this with a lot of my demos: this dash L and the F. So when I hit enter for the Lotions, the little dash tells me it’s a file. The L said it was Alina, and the D said it was a directory. And you’ll see a few others as you start really working with Linux and creating different types of files. But what we’re going to do is just look at some of the other commands that we can use to investigate what type of file these are. And one of the commands we used was the file command. So, if I type file and then press the tab key, I get my hard link. Well, we know that was a hard link that we made, but a hard link means that it’s pointing to the exact same location as the original, and it says that it’s an ASCII text file. In fact, if I type in a file and type in my link, the soft link that you see on this list, it tells me that it is a symbolic link, just as we expected. Now there is another command out there called stat.

Now, stat, we’re going to use the C percent options, but some of you are probably going to say, “Well, what on earth is that?” So, with your assistance, let’s complete the stat. Let’s pipe it to our more commanding screens so we can see it screen by screen. And we can see that C says that we’re going to display the file or file system status. And a dash C says we want to specify a format to use instead of the default. Well, now the format is this stuff down here. These are format sequences, and we’re going to use the capital F, the percent capital F, saying that I want to see the file type. You have many other options. Stats are a lot more than files. Stats are showing you the status of things.

And so you can probably gather that you could have a lot of fun with these options that you have for the status. Let’s clear our screen, and we’ll do STATIC percent with a capital F again, because we want to see the format or the file type. In this case, the C represents the format and the F represents the file type. And we’ll type in my hard link, and it will tell you it’s a regular file. If I do the same command, I’m going to hit the up arrow, backspace, and type in my link. And there it is, a symbolic link. Okay, so now we’re going to create a new file. We’re going to create one with the touch command. And remember, this just creates a file. It doesn’t do anything with it. And I’m going to call it my file tar, indicating that it’s a tape archive or a tar ball GZ, which is supposedly our way of saying that it’s a compressed archive. And we know that it’s neither one of those. It’s just an empty file that I created. But let’s see what happens now if I do an LS with the capital F and look at the color. It comes out as a different color.

Here, it’s symbolically telling us that it’s something different than some of these other types of files. And that’s where Linux has started to become a little more user-friendly. When we used to have a monochromatic screen, even if it was an external monitor, it was often just that. We didn’t get a lot of these colour coatings till a little bit later on. Anyway, you can see there that it is indicating to us that it must be different. And the reason is that those are standard extensions, even though we don’t use them technically, that indicate tape archives and that they’ve been zipped up or compressed. Well, let’s use the file command for my file, tar gz.

And you can see that the answer is basically empty. Okay, so “empty” is kind of an odd name because the colour coding gives me the idea that it’s supposed to have something in there or that it’s a special type of file, but the file command says, “Well, it’s supposed to be one of these things, but it’s just empty.” So let’s give it a shot right now. Let’s see if Stat gives us anything more about that information with the percent F for the format. And let’s try it again; my file entered successfully, and it says it’s a regular empty file. So look at that file. I just said it was an empty archive.

Basically, the stack command wasn’t fooled. It actually says, “Oh, I know what this is.” It’s just a regular file with a funny name, but it wasn’t fooled into thinking it was supposed to be an archive. All right, now the next thing we’re going to try to do is try to do a test command, and let’s see how well we can do that. I’m going to use a dash R instead of this bracket. Here we go. End bracket for Dash R and myhardlink TXT I didn’t get hit enter, and I’m not sure why. Let’s see if we can get that again. I’m trying to put in the shortcut for the test command, but what I have to do is put a little space in there between that bracket and the dash R. So anyway, I’m doing a test on this file, and basically the R is to see if I can read it. So now let me hit Enter. That was better. And a lot of you are probably wondering; you’re saying, “Well, where are the results?” Well, it is a test, so I have to actually use the echo with the dollar sign question mark to see what the answer was.

And zero is just that—it indicates there are no errors. The test was true, and it is a file that I can read. So, again, that’s another type of command that you can use to see what kind of information or what you can find out about a file, especially in the world where there are no true extensions and you’re trying to find out how things work. Okay, now we’re going to use the GUI to do some of the same things. I’m going to go to Places and open my home folder there. You can see my files. You can even see the icon that’s trying to tell me this is a tar file. In fact, what I’m going to do is right-click it and go to its properties, and it even says, “Hey, this is supposed to be a tape archive.” It’s been zipped or compressed. It has nothing in it. It’s a very small file. I can even go play with permissions or open it with whatever programmers are designed to work with those archives. Now, we know that this file is actually an empty text file.

There’s nothing in it. But because of the way the GUI is working and representing this, we are seeing it as an actual tape archive. We’re not seeing it listed here as the type of file that it is. When I right-clicked the contact and selected “properties,” it said it was a plain text document. So it might be an encouragement to you to say, “Well, I think that it makes sense that the command-line tools might be able to give me a little better picture of what these types of files are than actually right clicking them in the GUI.” And that is one of the reasons why I still prefer command line for so many tasks. All right, so that was a quick rundown of looking at the different types of files both through the command line and through the GUI, which was quite simple. Right-clicking properties.

24. Finding Files

Now, one of the cool things about Linux is its ability to find files. I’m not saying we couldn’t do it in Windows, but it wasn’t always as simple as it was in the Linux operating system. It is very easy in Windows today to search for objects. But back in the day, when we were having the bigger arguments about which operating system to use, people just said they loved the ability to find information inside their file structure with Linux. Now, when you consider that Linux has everything under the same root drive, you know it’s searching all of the attached media, everything that’s been mounted, and everything that’s been referenced, so you know it’s automatically going to follow or look for that, or it could potentially look at all of those places.

So you had a couple of commands; the first was the easiest, which was the find command. Find was simply an expression matching option that you have now. Expression matching could be as simple as putting in the name of a word or the name of a particular file and letting it look for that. But you could go very crazy with the regular expressions that you are capable of creating to be able to find specific types of things about files. So a lot of people really liked that about the find command. If you had a database of file names, you could use the locate command to search through that database. There is also an S locate command, which is basically a secure version of the locate command, trying to do the exact same thing while trying to keep those communications secure. There was also a command that helped you search for just executable file types. That command was known as the which WH. In other words, which of these is executable? And if you wanted to find and search for an executable and its source code and man files, you would use the whereis command to find all of those other structures.

25. Demo – Finding Files

All right. Now we’re going to take a look at the command “find.” Now again, find. I’m going to give you the help and pipe it to the More command, and you’re going to see some options here, of course, with the finding. Now, under “usage,” it shows you some examples of usage and some of the things that you can test for the operators, some expressions. And as you’re reading through this, you might say to yourself, “Let me hit the spacebar.” You might say, “Well, you know, this doesn’t really help me as much as I would like.” As you read some of these help files, you say, “I don’t know.” So you could try again with the “Find to try it here” option. and I think you might find this a little bit easier. It tells you that it’s a search file. It gives you the description: they hit the space bar. Then, at least here, it gives you the options for that slash or the dash.

Dash help was not so helpful. At least I didn’t think it was. And then not only does it break down those options for you up here, but it gives you some more examples of how you might use them down here. And as I hit the spacebar and go through all of the pages, you can see that there’s quite a bit; there are quite a few options that you can go through when using this command find. So what I’m trying to say in one way is that it’s probably not too conceivable that I’m going to show you every single one of those little commands, but you’re going to want to get used to it because it can be very helpful. Now I’m in my home directory, and I’m going to try this command, “find dot.” Now remember, “dot” means my current location at time zero. Now, that should show me all of the files at the location that I’m at that have been in my current directory and that have been accessed in the last 24 hours. So that’s pretty much all of them.

A lot of these are files that I’ve actually deleted. As a result, you can find them in the trash. So they’re giving me everything it found—certainly everything in my operating system—that matched that particular command. If I tried the find dot, my current directory time, and the number one, that means more than 24 hours ago and less than the last day. Now here it says that I’m not allowed to do that particular command. It gave me a permission denied message for some of the files that I was trying to find. So again, you have to deal with permissions as an issue. But the number one, as I said, was just trying to find those files more than 24 years ago, 24 hours ago, or less than 48 hours ago. And I don’t even think this operating system was up and running at that time. So I’m guessing that’s the reason why I was told that I didn’t have permission to run that particular command anyway. So you’ve got some options there with the find commands just to deal with time. Okay, so let’s try yet another command. Let’s try to find out. We’ll put in the Tilde type, which will be F, and the MMI N, which will be 90 going back in time.

And here what we’re trying to do is find all of the files of type “F” that have been modified within the last 90 minutes. Now what we’re going to do is we want to not only see those, but we’re going to pipe an extended argument to the LS LF command. So basically, I’m taking the results of the find command and asking it to put them into the ls command so that we can actually see them in a fashion that we’re kind of used to. And some of the files—the things that are files in the last 90 minutes in the directory of the route, which is where the tilde is designed to work—are showing me that information—the history and the authentication stuff—information or logs. By the way, the only things that have changed in the last 90 minutes are the dots. Okay, well, let’s try the Locate command.

When I try something as simple as Locate LS, it basically tells me that there is none in the current location that I’ve specified, that there is no such file or directory. “Locate” is just another way of saying that we were trying to find the destination of where the command LS is located. Locate is really intended to allow me to try to find my file, but there is no such file or directory. So anyway, it generally is just going to look for those particular letters, and it’s looking at the current destination that I was at. Let me clear my screen. Let’s do an LS-LF just to look and see what we have. So LS is not obviously in this current directory that we’re at. And even if I move to the root and LS LF, there’s nothing here that’s going to match those particular letters. But really, I was trying to find an executable, and so when we talked about looking for things, even if I tried the word “find,” I was going to be matching patterns. If I’m looking for an actual command, that’s where we use the command “which” for the LS.

And it basically tells you where the command is. In fact, in this case, the LS command has already been aliased for the actual color auto and the location of the actual file, which is in the bin directory, and the command is called LS, which gave me a lot more information. In fact, LS was just a way of saying what the command was, but it didn’t tell me where I could find it. I could also do the “where is it actually?” and when I do, the “where is it actually?” then goes out of the way to show me the location again of where that thing is going to be located. It also showed me, by the way, the path to the manual for the LS command as well. Remember, that’s what Wearies gave me—not only where the file is located, but where its manual is located as well. All right, so Locate, out of all of these, was probably the one command that wasn’t as great for looking for and finding information. Find worked out perfectly. It also gave us some options. Locate was a pattern matching programme, but when you’re looking for programs, that’s where you’re going to want to look at which, what, and where to be able to get that kind of information.

26. Topic C: Removable Storage

All right, so finally we’re going to look at removable storage. That’s a big deal. Today we’re buying terabytes that are the size of drives that you can stuff into your shirt pocket if you want to. I’m waiting for the terabyte USB drive. I’m sure that’s around the corner. Anyway, removable storage has a lot of potential files. Remember how we said that when you mount those, you’ll merge them into your system? 

27. Mounting Volumes

Alright, so when you mount a volume optical drive, USB drive, or CD as part of the optical drives, it merges the file system so that you have a single directory hierarchy where everything goes with that root forward slash, which is my topmost directory, if you will. Now, there are many different ways to go around and put these files in place.

The mount command has traditionally been the most commonly used. Now the mount command was basically typing the word “mount,” putting in a dash “t” to say “what type,” and then you would put in the device file mount point, location, and then any subsequent options. Now, I know that sounds kind of confusing. Basically, you were assigning a directory to represent the point at which you accessed that removable media. So if I put in a mount type and a file system for a USB drive and a path to where I’m mounting that, and the other options, right, the device file and the mount point both putting that in there. I basically made a kind of link, if you will, that said, if you go to this directory, it is actually going to show you the contents of that removable media. Now, most of your desktop distributions will automatically mount the CDs and your USB drives automatically.

That’s a benefit of what we have today, with everybody providing those types of wonderful applications and wonderful configurations for us so that we don’t have to do that all on our own. Now, at the same time, not every CD or DVD player might be recognized. That’s one of the hazards. One of the things that people didn’t like about Linux when they went over to the Windows world was that not every single bit of hardware was universally compatible with every version of Linux. As a result, even though we stated that these various types of variations will automatically mount that stuff, it may occasionally say I don’t recognise it. So you’ll need to add some more device files to get it recognized. Okay, yeah, that was painful. It was more painful than it is now. Today was very easy. Same with a USB drive. So anyway, those will often be put in automatically for you.

28. File System Types

Now file systems, as I said, are in a different unit. There are a number of different types of file systems. The ones we see for mass storage on large drives are frequently what we call the “Extended File System.” There’s the extended second edition, as well as the extended third and fourth editions, which are likely to be used on older floppies. You remember the days of three and a half-inch floppies, five and a quarter-inch floppies, and, dare I say it, eight-inch floppies?

Well, I don’t know; I never used an eight-inch floppy on a Linux machine. But we had those very small files, basically very small storage capacities, and so that was often the type of file system we saw: ext 3 extended file system for larger drives. and, as we said before, ext4 is an option to get up to one exabyte in file size. Now your CD-ROMs have some file systems that are read by all of the operating systems. They’re either the ISSO 9660 or the UDFS (Universal Disk File System), so that you can have your CD-ROM be read by any of the different operating systems that are out there. You’ll also have a USB file system today, the USBFS. The idea again is that if I have a common file system that I can use on any system, that’s great. And in the Windows world, the older file systems on the older floppy discs didn’t use Ext 2, they used what was called VFAT, or “Virtual File Allocation Table,” or Msdas’ variety of file system. So why do you need to have all that information in your head? Because when you manually use the mount command, one of the things the dash T is for is to tell me what file system type that drive is using.

29. Device Files

Now, the device files themselves, you have to remember, are where all the input and output is done, as though it’s working with files. And the idea was that when we looked at device files in that dev directory, those device files were designed to work with all of the different types of hardware. Now, that’s where I said if you’re missing a device file that talks to a special kind of hardware that doesn’t get recognized, that’s where you have to put one in there so you can get your version of Linux to work with whatever odd piece of hardware you purchased.

The idea, though, was to have everything work as a file. I didn’t have to create a programming interface for all of the different types of things that you could be using with.So all the IO would be done as though I were working with a file. So, if someone said, “Save this file to this hard drive, this USB drive,” I’d be working with the file that represents that drive and just writing to it. So it eliminated a lot of the back-end work that the operating system had to deal with. Windows does not work this way. Windows has an application programming interface for virtually everything that you’re going to plug in, so they have done the work to make it very interoperable with all of the hardware. You could say that one of the big benefits of having Windows is that you only have to write programmes to work with it.

Windows deals with the programming interfaces that touch all of the hardware. Also in the very same sentence, I could say that’s a weakness of Windows and one of the strengths of Linux. There you go, the perfect politician. It depends on what you’re trying to accomplish. I’ve always said that business needs Okay, so these device files are in the slashdev directory. These are special files that represent hardware devices. Now, some of these devices and some of their storage could be considered buffered or blocked storage devices or non-buffering character types of devices. That’s about how we transfer our data in.Now, technically, they all work with characters, whether it’s a block of them or just one. But the idea is still very valid about how I can write information into those devices. For instance, a large USB device or a hard drive Consider it a buffered system with a controller card; I can send a bunch of data; it can buffer that stuff and write it as needed, as opposed to a non-buffering, character-based retrieval or writing system. 

30. Mount Points

Now, a mount point is basically where your file systems are going to merge together. Remember, as I said before, that you’re going to take whatever this drive is as removable media or even another hard drive, and it’s going to become part of your file hierarchy system, your FHS. And when they access this folder or mount point, they’re actually accessing what looks like a directory but is actually going to represent the entire removable drive or media that you just put in. Now, in general, the MNT is where we put these mount points in the locations. Mount is what it is an abbreviation for. We also have Slash Media, which is a newer option that we use for removable media, but it’s still up for discussion as to which is the best choice to use for your USB drives or your CDROMs. Is it the Slash media or the Slash mount?

Now, if you choose to use a different mount point, let’s say a directory that already exists, then you have some problems. If the directory you’re mounting the drive to already exists and that directory had files in it, those files would be hidden and inaccessible until you unmounted the drive. If you mount your drive to a special folder, such as a system folder that you don’t have access to or that other users can’t access, you not only hide what’s inside, but you also hide the mounted device because it becomes inaccessible due to their permissions. So be careful about where your mounting points are. Choose them wisely. Generally, I would say you’re probably going to create a mount point that doesn’t already exist in a different directory.

Leave a Reply

How It Works

img
Step 1. Choose Exam
on ExamLabs
Download IT Exams Questions & Answers
img
Step 2. Open Exam with
Avanset Exam Simulator
Press here to download VCE Exam Simulator that simulates real exam environment
img
Step 3. Study
& Pass
IT Exams Anywhere, Anytime!