The command line interface (CLI) is a very powerful part of Linux. Linux beginners undoubtedly agree that at first it can seem a bit daunting and even dangerous. While it is true that there far more Linux commands available than most will ever want or need to know and that some of these commands are capable of wreaking havoc on your system if used incorrectly; it’s reassuring to know that help isn’t far away. While a new Linux user who is Internet savvy might be inclined to run straight to Google when they need help with a particular command or are searching for the command they need, this is not necessary. In fact, most of the time you don’t even need to leave your terminal. How is this possible? Simple, it’s the man command.
Getting Started With Man
Man is short for Manual, and basically means that by using the man command you are accessing the manual for a particular command. Let’s begin by exploring how man is used. Startup a terminal and type “man intro”. This brings up a basic introduction to user commands, and the CLI in general. Once you have finished reading the intro go ahead and exit the manual page by hitting the letter “q”. You should now be back at the command prompt. The next step you will want to take is to read the manual page for the man command itself. This is accomplished by typing “man man“. You may be beginning to see a pattern here. To see the manual for any command simply type “man command” at the prompt. You may also begin to notice a pattern in how the manual pages look. Most manual pages consist of several different sections. Let’s take a look at the sections available for mv command. Type “man mv” into your terminal.
This section shows the command and gives a brief description of the command. In our example we see that the mv command is used to move or rename files.
Here you can find precise information on using the command that you are viewing. This includes all the switches and options available for the command. The first two sections (Name and Synopsis) are meant to be a quick reference for using the command that you are viewing. Further sections dive a little deeper and give you even more information.
The description section breaks down all of the options available and tells you what they do. In our example with mv we can see that using the -i option prompts the user before overwriting any files that are being moved. Also note that we could also use –interactive to do the same thing.
Other sections that you might find in the manual pages are author information, bugs, copyright, files, see also, and examples. The two that might be worth mentioning are the See Also and Example sections. See Also gives you a list of other manual pages that may be relevant to the page you are currently viewing, while the Example section gives you a real world example of using the command you are viewing.
Searching For Commands
Let’s say that you want to copy a file but you are not sure what the command for copy is. Perhaps one of the most useful features of the Linux manual pages is the ability to search them. If we look at the manual page for the command man (Again that is “man man” at the command prompt) we can see that one of the options available is -k. What this option does is allow us to search the short description for keywords and display any matches. Back to our example for finding the command to copy files, let’s get to the command prompt and type “man -k copy“. This displays all the commands that have “copy” listed in the description. If you glance through the list of commands that man -k has found you should see “cp(1) -copy files and directories“. That looks like the command we need, but to be sure let’s look at the manual page for that command to be sure. “man cp” brings up the manual page for the command cp. As you can see by looking at the name and synopsis sections, this is indeed the command we need to copy a file.
Man I’m Glad There are Manual Pages
The man command has gotten me out of a jam on more than one occasion. I recommend that if you are just beginning to explore the CLI that you do a quick check in the manual before using any command. As I mentioned before the CLI is very powerful and it’s better to be safe than sorry when using it.