02. Command Help which, man, apropos, whatis

Oftentimes on the command line, you'll need some help with a command.

We can try Googling our answers, but a lot of what we're looking for is right in the command line!

Checking which executable is run

To see where an executable resides in the file system, we use the which command. This displays the path of the executable that will be executed.

So for example, if you have git installed, try:

$ which git
/usr/local/git/bin/git

Opening a command's manual page

If you need help understanding a command's function, we can use the man command, which displays a command's manual page. This is especially useful when we want to apply an option.

$ man ls

To move up/down, use j/k for line by line, or ^d/^u for pages at a time.

To quit the man page, press q.

Manual sections

Each manual page is divied up into sections. To jump to a particular section on a manual page, specify the number before the manual name.

$ man 3 ls
1
User commands
2
System calls
3
Higher-level unix programming library docs
4
Device and driver info
5
File descriptions
6
Games
7
File formats, conventions and encodings
8
System commands and servers

Searching for a man page with a keyword

If you want to search for a manual page you may do so with the -k option.

$ man -k search
... apropos(1) - search the whatis database for strings lfind(3), lsearch(3) - linear search and append lkbib(1) - search bibliographic databases ...

Searching for a command with apropos

If you're looking for a command, but not sure where to start looking, we can use apropos, which displays the appropriate commands.

This searches all executables for your key term.

Let's say I want to move my directory, but I either forgot or don't know which command to use. I can try typing:

$ apropos move
... mv(1) - move files rm(1), unlink(1) - remove directory entries rmdir(1) - remove directories
...

Very conveniently, I'm presented with a variety of commands that have "move" in its title or description.

Checking command description with whatis

Lastly, if we have no idea what a command is, use:whatis, which displays a brief description of a command.

$ whatis ipconfig
ipconfig(8) - view and control IP configuration state

This will give you a brief description of the ls command.

info: an alternative to man

A similar command to man is info, which uses hypertext formatting instead that allows you to traverse from section to section. To see a list of navigation keys, type the 'h' key after opening up an info page.

Take your Linux skills to the next level!

The Linux Command Line

Take your Linux skills to the next level! Try Linux & UNIX

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

$ Check price
39.9539.95Amazon 4.5 logo(274+ reviews)

More Linux & UNIX resources

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Ad