Pass CompTIA Linux+ Certification Exam in First Attempt Guaranteed!
Get 100% Latest Exam Questions, Accurate & Verified Answers to Pass the Actual Exam!
30 Days Free Updates, Instant Download!
XK0-005 Premium Bundle
- Premium File 344 Questions & Answers. Last update: Dec 03, 2024
- Training Course 145 Video Lectures
- Study Guide 1211 Pages
XK0-005 Premium Bundle
- Premium File 344 Questions & Answers
Last update: Dec 03, 2024 - Training Course 145 Video Lectures
- Study Guide 1211 Pages
Purchase Individually
Premium File
Training Course
Study Guide
XK0-005 Exam - CompTIA Linux+
Download Free XK0-005 Exam Questions |
---|
CompTIA CompTIA Linux+ Certification Practice Test Questions and Answers, CompTIA CompTIA Linux+ Certification Exam Dumps
All CompTIA CompTIA Linux+ certification exam dumps, study guide, training courses are prepared by industry experts. CompTIA CompTIA Linux+ certification practice test questions and answers, exam dumps, study guide and training courses help candidates to study and pass hassle-free!
Unit 03 - File and Directory Management
11. Files – Part
Alright, so when we talk about files, I guess the most obvious thing is creating and deleting. So we'll start off by talking about creating. In creating a file, we're going to expect, as I would in any environment, that you're using an application like OpenOffice to create a file. Now that seems to be a common thought—you know, hey, that's right, I'm going to open up Writer or Presenter and make a news slide show and save that thing or a new spreadsheet. Okay? But that wasn't always how we did things in Linux. We actually had to manually create a file, and we used a couple of commands. One was called Touch. Touch was a command that allowed us to create an empty file, or if the file already existed, it basically updated the metadata on that file. Now, we haven't talked about metadata, but that's the information about your information, like date created, owner, and that type of stuff. If we wanted to actually create the file and add text to it, or maybe we already had text that we wanted to append to an existing file, we would use the command T EE to do the same thing.
Now, today, you won't find a lot of people using Touch or T to do that. They're going to be using applications because I can open the application up, make the changes, and do all those things that make sense with creating files, managing them, deleting them, and everything else using a third-party application. Now, if you want, you can move a file. Now, if you want to move a file, the commands are pretty straightforward, but you have to remember that sometimes there are issues with moving a file. For example, if I move a file from one directory to another and the destination directory already contains a file with the same name, the operation will fail. But if you use F as an option, that will force the copy to occur, which would basically delete the file that was already in the destination directory without giving you any prompting. You could use the letter I as a command, and it would take you into an interactive mode where the process of moving is going to actually ask you questions. You know, what's the name of the file, and where does it want to go? It sort of guides you through the process of moving the file, almost like a wizard.
12. Files – Part
Again, that was moving. The same is true with copying. Whether I'm moving a file or copying, if the destination has a file with the same name, I'm going to get an error. And so that's where the F can help force that. Again. The I stands for interactive. Now, if you are moving, or I should say copying, a file from one location to a new one, and that new location already has an existing file by the same name, you could use the you, which means that all you're doing is updating the target file. Now, what this does is it actually takes a look at the file you're copying and the destination file, and it makes a comparison about which is the most updated, looking at its timestamp.
And if the file you're copying is newer, then it will replace the existing file. In other words, doing an update That might be great for when you're doing file transfers or collaborating on different files. And then, of course, the deletion of any of these files. The RM for removing also has a dash F to force the deletion, meaning that if there are any error prompts, like the file doesn't exist, you're not going to get those. It's just going to do it or not do it, but it's not going to sit there and interact with you. If you're deleting a folder and that folder has subfolders and files in that directory, you can use the R for what we would call recursive deletion, which means all those subdirectories as well as all the files in that path are going to get deleted as well. So that's a mass deletion. if you would.
Again, remembering that deletion always means deleting it from the file system, Things are still recoverable on the hard drive until you actually override it with new data. All right, so those are the basics of our files. Now, the good news again is that we're not going to deal with a lot of these command lines when we're using applications. Because in the application, if I update a file, it technically is going to delete the old one and put the new one in its place, and I'm done. If I'm copying, I can do that. I can use the save as all of that stuff happens in the application. So today our use of the actual commands to facilitate file manipulation is very slight. We're not going to be seeing it a lot. Now, if you move to a network device, like a router, a switch, or a PDA, there you're going to see more use of these commands to manipulate the files, configuration files, and user settings than you're going to see it on an operating system, whether as a client or a server. But it's still useful to understand the fundamentals of how to do these things via the command line.
13. Wildcards
Now remember that you can choose to use wildcards to delete more than one file at a time. Again, the idea is that you might have a series of files and you don't want to sit there and do the command one at a time, even though you could delete the first file, hit the uparrow, change the name of the file, and delete it. You can use things like the asterisk as a general wildcard. Now, as an example, we are talking about ways of using a wildcard. Let's say to list a series of files. And keep in mind that in the Linux environment, we don't use extensions like we do in Windows.
The extensions in Windows are tied to a programme that's going to auto-launch an executable. We don't have that; we don't need it; we can put them on, but they are basically just a name or part of the name of the file anyway. If you had a list of files that began with the word "My" and were in the TXT format, you could use a command like "ls" to list all the files that begin with "myasterix TXT." And what you're saying is anything that starts with the word "my" ends in TXT, regardless of how many characters are in between. Show me all those matches. Or you could do an RM and remove or delete all of those. If there was just one character missing instead of a number of characters, you could replace the asterisks with a question mark because that refers to any one character.
If there was a range of characters, it would have to be the numbers one through three or the letters A through F. And you can put it in a bracket and put it first. The dash is the final character in the series, or if it's not in numerical or alphabetical order but more of a randomness, you could have a comma c x comma y as your range of matching characters, which simply says, look for a single character within this range of the brackets. And that's my wild card. That's something that's probably easier to see than it is to describe. But the idea is that you have some options with the wildcards to make it easy to find files, whether for copying, deleting, listing, or whatever you want to do with those files, and you can use them to your advantage so you don't have to do things the old-fashioned way. For example, listing them all and scrolling through in the hope of finding what you're looking for, or removing them one at a time. You've got some options there.
14. Demo - Managing Files
All right, we are going to move to our home directory, and we are going to do some work with managing files. I'm going to go to Home > Live User, and there, if you didn't catch it, I hit the tab key to type in Live User. So quickly, a quick little LSD to see if there's anything in there. We have some directories, desktop documents, downloads, pictures, and some of that prebuilt stuff that was kind of helpful to make it. I hate to say this, but Windows is for everybody.
All right, so what I'm going to do is I'm going to create a new text document, and one of the command lines that we talked about is this one called Touch. Now, Touch just basically made the file for us, but it didn't allow me to put anything into it. So I'm going to appropriately name it my empty file. Now that's probably going to drive some of your Windowsfolk crazy because I didn't end up with a TXT. But that's okay. I'm going to do the LSF because it's not about extensions. Everything is just a file.
Now when I do the LSF, notice how the empty file, right, is a different color. I can't guarantee that all of your Linux distributions will colour-code your objects for you. But because of the F, I also don't see the forward slash behind it. So it gives me the good idea that that's not the directory. Now remember that one of the other LS commands I talked about was the LSD. So now when I bring that open, you see a little dash in front of my empty file. The D is a directory; the dash, which to most of us looks like it means empty, is an indication that this is a file. Okay? So we'll at least verify that it is my empty file because it's also zero bytes in size. So that's a good indication. Now let me clear off my screen. Remember, besides Touch, the command was designed to create a file and allow you to enter text at the command line.
So I'm going to say my not-empty file. So I'm going to call this file "My Non-Empty File." When I hit Enter, I'm now going to be able to start typing whatever I want to type. Remember that because I typed the carriage return and enter, your text will frequently be duplicated. It's kind of echoing back to you what's being written into the file. So I didn't just put that line in twice.
And how's the weather? All right, well, I can tell you it's not nice right now where I'm at, but I'll leave it at that. Now, when I'm done typing some stuff in, ctrl-C is my way of saying, "OK, I'm done." And one of the quick little commands that we use to look at the contents of a text file is just to sit there and type in "cat." As you may remember, if I hit the tab key, I have two files that start with the word my. Let's just see what happens. I hit the space bar, and now you're probably wondering, "Whoa, what did I do?" Well, I have two files that both start with my underscore.
So it completed that portion of what was common to both those files. I'm going to tab again. Hit the tab twice. There we go. And now it says, "Okay, look, there they are: the names of the files." All right, so I'm going to copy my not-empty file. I started typing "non." I hit tab again to finish it. You'll appreciate the tab because it will save you from having to type every single command. Anyway. So Kat's job was to take the contents of that text file and spit it out onto the screen.
And it certainly did. It said, "Hello, world." How's the weather? All right, so far, so good. I'm going to clear this up again. I like to have things out of the way as I go with each of these concepts. You may just choose to continue typing on. It doesn't affect your history because, look, here's the history, see? All right, now that I've proven that to you, I've got to clear it again. OK. Let's start with L. We have two files now: my empty file and my non-empty file.
The next thing we're going to do is copy. We're going to copy my nonempty file into a new file called my copied file. Now, because I'm not changing the directory, I'm putting it in the same directory. You don't see me adding any paths. That means that this copy is assuming that I'm going to create this new file in the same location that I'm in right now. I'm going to do the LS dash. Let's do L with a capital F. So we can see the directory markers at the end of the directories. And you can see that my non-empty file that was 30 bytes of data has now been copied to my copied file, and it was also 30 bytes of data.
So it looks like we've done pretty well at taking care of what we want to do. But let's see if I hit this up arrow. That's the same command I just typed a second ago to copy my non-empty file into my copy file. Let's see what happens when I hit enter. All right, now it's kind of saying, "All right, do you want to overwrite my copy file now?"
That's something I like because it's once again taking care of me. It's saying, "Hey, look, you've already got a file there." I'm going to say "N" for no. It says you already have a file there. And if you try to do that copy, you're going to have problems. Now, another option could have been—in fact, let me hit the up arrow to get to that file. Remember to look at the flashback by pressing F. To proceed, I'll type "interactive" in the space provided. I'm going to try the same thing. And in this case, in the old days, you would have needed the I to get this message rather than just getting an error. But it's called the interactive mode, and that's designed to help you get through any troubleshooting or errors, but it happened automatically, as you can see.
All right, well, let's try that same command. I like this control A and this control F. To move forward, I'm going to delete CTRL D, that letter, type in F, and then hit Enter. And notice here again that even with trying to put the force on, it still says, "Do I want to overwrite my copied file?" So we talked about some of those command-line options, but you may see some differences in how they work depending on the type of distribution that you're using, some of which are optional. In fact, let's do the CP help.
And as you can see, I need to scroll back up a little. Now you can see some of these options, and there's the F that says if the existing destination file can't be opened, remove it and try again. So that was the point of what I was trying to do. I asked for an interactive prompt before overwriting, but one of the challenges is that as we continue to evolve in the Linux world, some of these command lines, as you can see here, really were just being assumed all the way through, trying to make sure you didn't have any errors or cause yourself any harm.
One of the things that turned a lot of people off about Linux was that it did exactly what you told it to do. And if you told her to do something that was not beneficial to you, it's too bad she did it anyway. So it's kind of protecting you a little bit now. Okay, so now I'm going to remove the file—in fact, that's LSL—so we can see the list again. I'm going to remove RM, and it's not Delete, not Dell, and I'm going to remove My, and I'm going to type in the letter C because that's enough to be specific to the file. Hit the tab key. I'm going to remove my copied file, and it says, "Do you want to remove the regular file or my copy file?" I'll explain why for yes. Now let's do the LSL.
And now you can see in the new listing that my copied file is missing. So again, it was kind of put into that little bit of an interactive mode. Now, sometimes you might want to do an LSA list; you might want to do the capital L, but you don't want to see everything. So I'm going to type in my asterisks, and using the asterisks as a wild card, I've said, "Let's list everything with the same long format." Show me if it's a directory or not. And by my underscore, Asterix was referring to files that begin with the letters my underscore. As a result, it was a nice way to reduce the output of your list just a little bit. So a lot of people like doing that. Okay, now if I wanted to, I suppose I could go out there and remove files. In fact, let's try that same wildcard, my underscore asterisk. Let's see what happens if I use that wildcard with my remove command and it says remove the regular empty file, and I'm going to say yes, and then it says, "You want to remove the nonempty file?" I'm going to type "Y" again for yes. And now, just like that LSL, all those files are gone.
So you can also use the wild card with many of your other commands, including remove. So RM asterisks by themselves might be dangerous because you're going to destroy everything that's in that subdirectory. Okay, so that's about it for dealing with your files. Let's minimise that screen in the command line and navigate to our Places and Home folders over here. And here in my home folder, I'm going to maximise this thing. And from this point, I'm going to right-click and create a document and an empty file. That file, of course, can be called my "underscore empty file." And what I'm attempting to do is replicate what we just did via the command line. Let me right-click and create another document, another empty file.
This one I'm going to call my "non-empty file." But we know it is not going to be empty. I'm going to double-click it. All right, now I'm going to type some text in here. Hello, world, how's the weather? I know you're thinking you're watching a rerun, but really, I'm just trying to demonstrate that everything I did with the command line, I can do with the GUI. I'm going to file. I'm going to save this and close it. And, of course, this is no longer an empty file. I'm going to see if I can do this as a list. So now, as a list, you can actually see the size. Did you see where I went? I went to View, and I can see the size of these things. I can see what type of document it is, but I'll go back to the cool little icons again. I like the pictures.
Okay, so from there, I've got the copy thing. So I'm going to click on this particular file, and if I right-click it, I can copy it. Let's see how our Windows commands do. I'm going to do a ctrl-c. And when I did that, notice that down the bottom of my status bar, it says, "My nonempty file will be copied to the selector," the paste command. So I'm going to click anywhere in this blank area. I'm going to do Control V. Alright? Now, when I did the copy and paste, of course, it says, "Hey, this is a copy of the file." They had to give it a different name. I'm going to hit F2, the key command F2, so I can call this my Oops lowercase. Here is my copied file. Okay. And then you can see how it quickly moved things around so that they're still alphabetized. All right. From there, we executed some of the previously seen commands.
You may or may not like using one over the other, which is why I'm showing you both so you can have some fun with it. The next thing to show you, of course, is that once you make these files, I can right-click them and delete them. It would be moving the file to the trash. If I go to Edit and move it to Trash, I can do that, or I can just hit my delete key on the keyboard and get rid of that thing as well. If I go to edit and, let's say, select items matching and put in the pattern underscore, and then the asterisks click on OK, Notice how it selected all those items for me. I hit the delete key, and they're gone. So it's similar to the wildcard we used in the command line. So there you have it, hopefully working with files this time in both the command line and the GUI. It doesn't seem like a big mystery, and actually, I think it's very straightforward type of stuff.
15. The vi Editor
Now, one of the earliest things we used for creating files was called VI. I'd like to think that it meant "very irritating," but it didn't. It was designed in the 1970s as a graphical interface, despite the fact that it doesn't look like one. Its name was Visual, and they called it VI. The reason it was called VI or considered "visual" is because it opened up a window that looked like a command-prompt window. It looked like a shell window, but really, it was just the first version of Notepad, and you would type in your text. Now, it didn't allow me to create these cool, bold types of things. I didn't have aerial font in Times New Romantic, maybe, but back in the old days when I first saw VI, for me, it was in the early 80s. We didn't have those options. It was just a text editor.
And it had two modes. It was editing mode, in which I was adding text, changing text, and writing whatever I was writing, and a command mode that let me save my file, rename the file, delete certain lines, or do whatever I wanted to do. It was a very popular tool that we used for programming back then. We did a lot of practise in the languages of Pascal and C even before C, but even after C we did a lot of it in VI, where we were just literally typing our source code from start to finish, saving it as a single file that we could send through a compiler later to see if we had any errors. That's what it was. Job. So in a way, it was a visual tool, because when we used the commands to save our file, it did that. It saved the file, created it, put our stuff in there, and acted very much like a graphical user interface. just didn't look very graphic.
CompTIA Linux+ certification practice test questions and answers, training course, study guide are uploaded in ETE files format by real users. Study and pass CompTIA CompTIA Linux+ certification exam dumps & practice test questions and answers are the best available resource to help students pass at the first attempt.