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 dash P for permissions?
We can get a quick reminder with LS dash
dash
help.
This will show us a lot of output.
But if we scroll up, we'll find what we're looking for the dash 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 dash dash help option for commands will be very helpful when we forget
about these options and we will because there are so many of them for each command
for LS. That's OK. 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 dash dash help option for commandss will
very often be helpful when we forget about these options.
And we will because there are so many of them for each command.
Let's take journal CTL as an example, a command that lets us read system logs.
We'll type in journal CTL dash dash 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
journal CTL.
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 and 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 manpage for man itself by typing in man man.
Now if you want to read the manpage about printf the command,
you tell man that you want to consult printf
from section one like this
type in man.
One printf.
If you want to read about printf the function, then you tell man,
you want to look at section three
man three printf.
Now it's useful to know that during online exams,
the Linux Foundation will let you use man and dash dash help.
So try to use dash dash 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 manpage 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 air.
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.
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 two
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 a
proposes to only filter out results that lead to commands from these categories.
We do this by using the dash S option followed by a list of the sections we need.
For example, a
proposes dash S one comma eight director
and now we can spot what we're looking for more easily
notice how MKD IRS description contains the word directories.
If we would have used the word directory in our apropos search,
this command wouldn't have appeared since
directory wouldn't have matched directories.
This is something to keep in mind when you want to
make your searches as open as possible and match more stuff.
Another thing that will save a lot of time is auto completion
type in system C
and I press tab
and you 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 system CTL.
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 the suggestion list.
Now to add to that
type in system CTL list dash dep,
press tab
and now dependencies will get added on to the
end and you get system CTL 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 autocomplete 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 saver 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 autocompletions also work for file names or directory names,
try LS dash U and press tab
or LS dash us R
tab tab.
And now we can see directories available in slash us R
without even needing to explore this directory with LS beforehand.
And if we have a long file name, like wordpress underscore archive dot TGZ,
we might be able to type wor and press tab and that long name will be autocompleted.
Well, 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 dash dash 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 LF CS 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 manpage or a help page,
you'll be able to pass the exam much more easily.