• A QUICK LOOK AT WILDCARDS
  • Filtering with grep
  • find /etc -type f -name apache2.\*




    Download 7,3 Mb.
    Pdf ko'rish
    bet36/125
    Sana14.05.2024
    Hajmi7,3 Mb.
    #232858
    1   ...   32   33   34   35   36   37   38   39   ...   125
    Bog'liq
    linuxbasicsforhackers

    find /etc -type f -name apache2.\*
    /etc/apache2/apache2.conf
    When we run this command, we find that there is one file in the /etc
    directory that fits the 
    apache2.*
    pattern. When we use a period followed 
    by the 
    *
    wildcard, the terminal looks for any extension after the filename 
    apache2. This can be a very useful technique for finding files where you 
    don’t know the file extension.
    When I run this command, I find two files that start with apache2 in the 
    /etc directory, including the apache2.conf file.
    A QUICK LOOK AT WILDCARDS
    Let’s say we’re doing a search on a directory that has the files 
    cat

    hat

    what

    and 
    bat
    . The 
    ?
    wildcard is used to represent a single character, so a search 
    for 
    ?at
    would find 
    hat

    cat
    , and 
    bat
    but not 
    what
    , because 
    at
    in this filename is 
    preceded by two letters. The 
    []
    wildcard is used to match the characters that 
    appear inside the square brackets. For example, a search for 
    [c,b]at
    would 
    match 
    cat
    and 
    bat
    but not 
    hat
    or 
    what
    . Among the most widely used wildcards 
    is the asterisk (
    *
    ), which matches any character(s) of any length, from none to 
    an unlimited number of characters. A search for 
    *at
    , for example, would find 
    cat

    hat

    what
    , and 
    bat
    .
    Filtering with grep
    Very often when using the command line, you’ll want to search for a par-
    ticular keyword. For this, you can use the 
    grep
    command as a filter to search 
    for keywords.
    The 
    grep
    command is often used when output is piped from one com-
    mand to another. I cover piping in Chapter 2, but for now, suffice it to say 
    that Linux (and Windows for that matter) allows us to take the output of one 
    command and send it as input to another command. This is called piping
    and we use the 
    |
    command to do it (the | key is usually above the 
    enter
    key 
    on your keyboard).
    The 
    ps
    command is used to display information about processes run-
    ning on the machine. We cover this in more detail in Chapter 6, but for this 


    Getting Started with the Basics
    13
    example, suppose I want to see all the processes running on my Linux sys-
    tem. In this case, I can use the 
    ps
    (processes) command followed by the 
    aux
    switches to specify which process information to display, like so:
    kali >
    ps aux
    This provides me with a listing of all the processes running in this 
    system—but what if I just want to find one process to see if it is running?
    I can do this by piping the output from 
    ps
    to 
    grep
    and searching for a 
    keyword. For instance, to find out whether the apache2 service is running, 
    I would enter the following.
    kali >

    Download 7,3 Mb.
    1   ...   32   33   34   35   36   37   38   39   ...   125




    Download 7,3 Mb.
    Pdf ko'rish