summaryrefslogtreecommitdiff
path: root/src/Searching_for_a_Command_in_Linux.adoc
blob: 51bb6b8c05e3d0eb08bbf8ea0fda0baebe097c90 (plain)
    1 Searching from Command Line in Linux
    2 ====================================
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 
    6 
    7 == {doctitle}
    8 
    9 For those of us learning command line for the first time, it can be a pretty
   10 intimidating thing. A terminal in the hands of a person with a black belt in
   11 shell commands can be far more powerful than a GUI (graphical user interface).
   12 However, becoming a so-called black belt takes a lot of time and practice.
   13 Unlike a GUI, you have to memorize the commands you need...mostly.
   14 
   15 I say mostly because there is a command in Linux that is probably one of the
   16 singly most used commands out there. That command is known as the *man*
   17 command. In interviews in response to a question you don't know, "I would just
   18 read the man pages" is the equivalent of "Jesus is the answer to everything" in
   19 church. The great thing is both actually work (not to put an obvious religious
   20 statement in my blog here).
   21 
   22 Man is short for manual. It's like reading your car manual, but for a command
   23 in your shell. For instance, if you run
   24 
   25 ----
   26 man mkdir
   27 ----
   28 
   29 You see something an explanation of what the command does, how to use the
   30 command, and the various advanced features you can do with it.
   31 
   32 But what ifyou don't know what command to use?
   33 
   34 Thankfully, there is a relatively simple solution to this. All you really know
   35 is how to describe what you want to do in a simplistic way.  Ladies and
   36 gentlemen, that command is the man -k command. I hope you all didn't pay full
   37 price for your seats because you'll only be using the edge.
   38 
   39 
   40 [[man--k-command]]
   41 == man -k <command>
   42 
   43 The man -k command/switch searches all of the commands that have man
   44 pages for what you typed in to search for. It then returns the command
   45 name with a short explanation of what it does. Let's get some practice
   46 in.
   47 
   48 Say you want to search for how to create a directory. We're going to run
   49 
   50 ----
   51 man -k "make directories"
   52 ----
   53 
   54 And it will return
   55 
   56 ----
   57 mkdir  (1)              make directories
   58 ----
   59 
   60 Cool, huh? Now, there is a complication to this. If you want to search
   61 for something and the exact text you type isn't in the manual exactly as
   62 you typed it, it will not be returned. For instance...
   63 
   64 ----
   65 man -k "create directory"
   66 ----
   67 
   68 ...will return nothing becuase the manual for mkdir has "make directories" in
   69 it, not "create directory". How do we get around this?
   70 
   71 Wild cards and very simple one word searches.
   72 
   73 
   74 [[wild-cards]]
   75 == Wild Cards
   76 
   77 Now, let's say you're not sure if the manual you're looking for has the word
   78 directories, directory, or just dir in it. We need a way to search for multiple
   79 forms of a word. We do this with what is called a wild card character. Run the
   80 following command: <pre>man -k dir*</pre>
   81 
   82 This will search the manuals for any words that start with dir and end with
   83 anything (including spaces or other words).
   84 
   85 Once you've found the command you want, you can simply type <pre>man
   86 <command></pre> and you can read the manual until you're heart is content, or
   87 even until it stops!  :)
   88 
   89 On a similar note, to get out of reading a manual, **press the letter 'q**'. I
   90 can't tell you how long it took me to figure that out when I first was learning
   91 about the man pages. I guess now I should be ashamed of myself.
   92 
   93 
   94 Category:Linux
   95 
   96 
   97 // vim: set syntax=asciidoc:

Generated by cgit