From the course: Linux Foundation Certified System Administrator (LFCS) Cert Prep
Read and use system documentation - Linux Tutorial
From the course: Linux Foundation Certified System Administrator (LFCS) Cert Prep
Read and use system documentation
- [Instructor] There will be many commands that we'll use in Linux, and each command has a lot of command line switches. Now, how are we supposed to remember them all? As we use command repeatedly, we'll learn everything about it and memorize what each option does. But in the beginning, we might forget about these options just after one or two uses. That's why Linux gives you multiple ways to access help manuals and documentation right from the command line. Let's say you want to see that long listing format with LS to get a look at the file permissions, but you forgot what the correct option was. Was it -P, for permissions? We can get a quick reminder with ls--help. This will show us a lot of output, but if we scroll up, we'll find what we're looking for, the -l flag in this case. Now, you can see here how command line options are sorted alphabetically and described with short text. That's why the --help option for commands will be very helpful when we forget about these options, and we will because they are so many of 'em for each command. For LS, that's okay because it's a pretty simple command. Other commands however, are very complex, and we need to read longer explanations to understand what they do and how we use them. That's why the --help option for commands will very often be helpful when we forget about these options, and we will because there are so many of 'em for each command. Let's take journalctl as an example, a command that lets us read system logs. We'll type in journalctl--help, and it will show us this. Now, notice this opens in a slightly different way. Look at where it says "lines one through 27," in the bottom left corner. This opened what Linux calls a pager. It's simply a text viewer of sorts that lets us scroll up and down with our arrow keys or Page Up, Page Down. To exit this help page, press "Q." Now, all important commands in Linux have their own manuals, or man pages. To access a command's manual, enter man, name of command. Now in our case, we'll use man journalctl, and now we get a short description of what the command does in name, general syntax of the command in synopsis, detailed description of the command, how it works and so on in description, and some manual pages even have examples near the end of the manual. Now, sometimes, you will have two man pages with the same name. For example, printf is a command, but printf is also a function that can be used by programmers. Manual pages can fall into one of these categories, and we can see these by looking at the man page for man itself, by typing in man man. Now, if you want to read the man page about printf, the command, you tell man that you want to consult printf from section one, like this. Type in man 1 printf. If you want to read about printf the function, then you tell man you want to look at section three, man 3 printf. Now, it's useful to know that during online exams, the Linux Foundation will let you use man and --help, so try to use --help if you forget a command line option because that gives you the fastest results. Diving deep into a manual page will eat up some time. Now, this is all well and good when we know what command we want to explore, but what if we can't even remember the name of the command that we need to use? Imagine you forgot the name of the command that lets you create a new directory, how would you search for it? Apropos is a command that lets you search through man pages. It looks at the short description of each man page and tries to see if it matches the text that we enter. For example, with the next line, we can search for all man pages that have the word director in their short descriptions. We'll use director, and not directory. Director will match commands that contain the word directory, but also the ones that contain directories. So, we'll keep it more generic this way. Now, the first time we run apropos director, we'll probably get an error. That's because apropos relies on a database. A program must refresh it periodically. Since we just started this virtual machine, the database hasn't been created yet. We can create it manually with sudo, space, mandb. Now, in servers that have already run for days, there should be no need to do this as it will be done automatically. And now, the apropos command should work. We'll type in apropos director, and if we scroll up, we can see the entry we're looking for, mkdir. But those are a lot of entries, it makes it hard to spot what we're looking for. You see, apropos doesn't just list commands, it also lists other things we don't need currently. We see stuff like "2," that signals the entry is in section two of the man pages, and section two contains system calls provided by the Linux kernel. That's just a little too advanced for our purposes. Commands are found in sections one and eight, so we can tell apropos to only filter out results that lead to commands from these categories. We do this by using the -s option, followed by a list of the sections we need. For example, apropos -s 1,8 director. And now, we can spot what we're looking for more easily. Notice how mkdir's description contains the word directories. If we would've used the word directory in our apropos search, this command wouldn't have appeared since directory wouldn't have matched directories. This is something that keep in mind when you want to make your searches as open as possible and match more stuff. Another thing that'll save a lot of time is auto completion. Type in systemc, and then press Tab, and you'll get systemctl. Although this is not technically system documentation, it can be helpful. Many commands have suggestions on what you can type next. For example, try this: type systemctl, add a space after the command, don't press Enter, and now press Tab twice. You'll get a huge list of suggestions. This can help you figure out what your options are for that command. You shouldn't always rely on this, it's not necessary that absolutely all options are included in this suggestion list. Now, to add to that. Type in systemctl list-dep, press Tab. And now, dependencies will get added onto the end and you get systemctl list-dependencies. This is Tab auto completion, and many commands support it. When you press Tab twice, if your command interpreter can figure out what you want to do, it will automatically fill in the letters. If there are many auto complete suggestions and it can't figure out which one you want, press Tab again, and it will show you the list of suggestions that we observed earlier. These will be huge time savers in the long run, and they might even help you in the exam to shave off a few seconds here and there, which might add up and let you explore an extra question or two. Now, Tab suggestions and auto completions also work for file names or directory names. Try ls/u, and press Tab; or ls/usr, Tab, Tab. And now, we can see directories available in /usr, without even needing to explore this directory with ls beforehand. And if we have a long file name, like wordpress_archive.tgz, we might be able to type wor, and press Tab, and that long name will be auto completed. While manuals and help pages are super useful, the first few times you use them, it might be hard to figure out how to do something with just that info alone. So we recommend you take a command that you know nothing about and try to figure it out with just man and --help, and try to figure out how to do something. This practice will help you develop the ability to quickly look for help when you're taking the LFCS exam. There will be questions about theory that you either don't know about or just forgot. If you know how to quickly figure out the answer with a man page or a help page, you'll be able to pass the exam much more easily.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Log into local and remote graphical and text mode consoles7m 18s
-
Demo: Log into local and remote graphical and text mode consoles2m 30s
-
Read and use system documentation8m 5s
-
Create, delete, copy, and move files and directories11m 4s
-
(Locked)
Create and manage hard links7m 5s
-
(Locked)
Create and manage soft links3m 14s
-
(Locked)
List, set, and change standard file permissions13m 48s
-
(Locked)
SUID, SGID, and sticky bit7m 18s
-
(Locked)
Search for files12m 33s
-
(Locked)
Compare and manipulate file content9m 6s
-
(Locked)
Pagers and VI demo5m 56s
-
(Locked)
Search a file using grep5m 6s
-
(Locked)
Analyze text using basic regular expressions7m 46s
-
(Locked)
Extended regular expressions10m 3s
-
(Locked)
Archive, back up, compress, unpack, and uncompress files (optional)5m 3s
-
(Locked)
Compress and uncompress files (optional)4m 27s
-
(Locked)
Back up files to a remote system (optional)3m 52s
-
(Locked)
Use input-output redirection (e.g. >, >>, |, 2>)12m 47s
-
(Locked)
Work with SSL certificates17m 30s
-
(Locked)
Git: Basic operations8m 2s
-
(Locked)
Git: Staging and committing changes9m 31s
-
(Locked)
Git: Branches and remote repositories18m 18s
-
-
-
-
-
-