Bash - man oh man

This article concentrates on the 'man' command. Learning how to use the manual will save you time and effort in finding answers and make you a happy server admin.

In the previous Bash - who, where and what article we were introduced to some basic Bash commands but we ended by adding some conditions to a command in the form of:

ls -al

I'll now explain that the 'a' is short for 'all' and means 'do not ignore entries starting with .' (i.e. show those hidden files we talked about) and the 'l' means 'use a long listing format'.

How do I know these things? By using the 'man' command. The man command will give me a manual entry. Try it now:

man ls

If you are anything like me you will cringe looking at that. Don't be fooled either way: this is typical of the functional style of a 'man' output but it is also a very powerful tool.

Have a look at the SYNOPSIS paragraph. It tells you exactly in what order the command is used. i.e. 'ls' first, then any options, then a file or directory to list details from.

The DESCRIPTION area can be overwhelming with many dozens of options but let's take a look at the two we chose for the 'ls' command:

The first one was 'a'. We can see it already without scrolling down:

-a, --all
        do not ignore entries starting with .

Have a think about what it says and what command was actually given. Do you note the different way the 'a' command could have been given?

Well, we could have used the longer version:

ls --all -l

That gives exactly the same output as the shorter version:

ls -al

Which style you use or whether you mix the long and short styles is entirely up to you.

Before we go much further, I should mention that to leave the manual and return to the command prompt, press the letter 'q'.

This is also where programmes like 'screen' come in useful (See the last third of page 2 of the Ubuntu VPS article for more on screen) as you can simply flick from one terminal to another without exiting the manual.

Now we need to find the 'l' option. To scroll down the manual we have a couple of choices; we can use the down arrow to scroll line by line or we can use the 'Page Down' button scroll by a full page (a page being the size of your terminal so you won't miss anything).

Scroll down to the description of the 'l' option:

Again, a nice and simple explanation. As it happens, the 'l' option has no long version as an alternative so you're stuck with using '-l'.

-l     use a long listing format

As you can see, there is plenty of information at your fingertips. Admittedly, it can seem a bit daunting to be presented with a sterile ream of information, but once you see it for what it is, i.e. simple explanations, it becomes a very useful and powerful tool.

Pretty much every command you will come across will have a manual entry - try it on some of the commands we've used already such as 'pwd' and 'who'.

To learn more about the 'man' command we can, of course, enter the command:

man man

In case anyone is still stuck inside the manual, don't forget you need to press 'q' to exit back to the command prompt!

Next we'll look at directory manipulation - an essential skill.

PickledOnion.

Digg it | del.icio.us | reddit | StumbleUpon

Comments are closed for this article.