课程: Linux: Files and Permissions

Get help with commands

- [Instructor] Knowing how to get information about commands in Linux is paramount to understanding such a powerful operating system. You can use the methods in this video to gather information about any command I use in this course or any other course. Let's start by using the dash dash help option built into most commands. Open a terminal by putting your mouse pointer in the top left-hand corner and typing terminal. You can drag this to your application bar if you haven't already done so. From this point on, you can go into overview mode and click on the terminal icon. Now let's get the help information for the grep command. The grep command is a very useful tool for searching through text and is perhaps my favorite command. Type in grep space dash dash help and hit enter. The dash dash help information is built into almost all Linux commands, so you can usually count on it being there. If the output is too long, use the scroll bar or press shift page up to scroll up. At the top of the output, it shows the command syntax or usage followed by all of the options. Some commands may not have the dash dash help option. We can also use the help command to get the syntax. Let's use the help command to get information on the CD command. We'll use CD because the help command has no information on grep. Type in help, space, CD, and hit enter. Between the dash dash help option and the help command, we should be able to get help on most any command, even though that information may be brief. Most commands have a more in-depth manual written for them and we can access those manual pages using the man command. To get the manual page for grep let's first type in clear, to clear our screen, and then type in man space grep and hit enter. Most man pages are structured in a certain manner. They start with a name and a short description. Then they show the command usage followed by an in-depth description of the command. Sometimes the options to the command are included in the description, but other times there may be a specific options section. This is where I spend most of my time after I've noted the syntax. the sections after the options can vary but take note of the see also section near the bottom. This can be very useful when learning Linux as viewing the man page of a command similar to what you need may contain a clue on the right command for the job in the see also section. This can be invaluable for learning new commands related to your current task. Some man pages have examples near the bottom which I think should be the standard practice. The quality of man pages vary depending on the specific project creating them. All man pages reside in man page sections. We can see that our grep man page is in section one by looking at the text on the top line. Now press Q to quit the grep man page. To see the man page sections, we can view the man page or man pages. Type in man space, man, dash pages and hit enter. Section one is for programs. Section five is for file formats and configurations and so on. If you want more information on any man page section you can just check the man page for the section itself. Press Q to quit and then type in man space one space intro, and hit enter. And man will tell you about the first section. Here it says that section one of the manual describes user commands and tools. Press Q to quit. There may be more than one man page for a command. We can search through the man pages but first we need to create a search database. We will need to elevate privileges for this, so type in sudo, space, mandb, and hit enter and then type your password in. It may take a moment to create the manual database. Once that's done, let's find the man pages with the name crontab. We'll use the find option by typing in clear and then type in man space dash F space crontab, and hit enter. We can see that crontab has three man pages and sections one, one P, and five. Section one is for commands. Section one P is for POSIX compliant commands. POSIX being the standard that defines the Unix-like operating systems. In many cases, Linux may have a POSIX compliant command as well as in non-POSIX complaint command. And lastly, section five is for file formats. Or in this case, the crontab configuration file. You can specify a man page section on the command line to get the right man page. For the crontab man page in section five, type in man space five space crontab and hit enter. And then press Q to quit this man page. If you want to do a more exhaustive search through the man pages, you can use man-K. Let's search for crontab again. Type in man space dash K space crontab, and hit enter. Now we see we have five man pages including one for something called Anacron tab. Now, you know how to get help for commands on the command lane. I recommend as you go through this course and others, you look up the commands with the dash dash help option as well as use the help and man commands. It may also be helpful to create a list of commands that we cover, and add to it in each course.

内容