However, egrep is deprecated, as grep -E is the preferred syntax. The egrep command is essentially the same as the grep -E command. The ls -l | grep audit command returns a long listing of any files in the current directory whose name contains “audit”. In addition to searching the contents of files, you can use grep to search a directory in order to locate a certain file. Several common ones are described in the following table. The syntax of the grep command is: # grep Instead of reading the entire log or stepping through a search term in a text editor, you can simply print all of the relevant lines to the screen with the grep command. For example, you may want to audit a user’s login events by looking at an access log. In this way, you can use grep to both processes a text file and read the contents that are most pertinent to you. As output, grep displays each full line of the file that your search pattern was found in. Unlike find or locate, it is not limited to finding file names it is most often used to search the contents of a file for a particular string of text. * Adds a searching pattern to the internal array.The grep command, in its most basic form, is a search tool. * Command-line flags */ unsigned long long Aflag /* -A x: print x lines trailing each match */ unsigned long long Bflag /* -B x: print x lines leading each match */īool Hflag /* -H: always print file name */īool Lflag /* -L: only show names of files with no matches */īool bflag /* -b: show block numbers for each match */īool cflag /* -c: only show a count of matching lines */īool hflag /* -h: don't print filename headers */īool lflag /* -l: only show names of files with matches */īool mflag /* -m x: stop reading the files after x matches */ long long mcount /* count for -m */īool nflag /* -n: show line numbers in front of matching lines */īool oflag /* -o: print only matching part */īool qflag /* -q: quiet mode (don't output anything) */īool sflag /* -s: silent mode (ignore errors) */īool vflag /* -v: only show non-matching lines */īool wflag /* -w: pattern must start and end on word boundaries */īool xflag /* -x: pattern must match entire line */īool nullflag /* -null */ char *label /* -label */ const char *color /* -color */ int grepbehave = GREP_BASIC /* -EFGP: type of the regex */ int binbehave = BINFILE_BIN /* -aIU: handling of binary files */ int filebehave = FILE_STDIO /* -JZ: normal, gzip or bzip2 file */ int devbehave = DEV_READ /* -D: handling of devices */ int dirbehave = DIR_READ /* -dRr: handling of directories */ int linkbehave = LINK_READ /* -OpS: handling of symlinks */īool dexclude, dinclude /* -exclude-dir and -include-dir */īool fexclude, finclude /* -exclude and -include */ enum , # endif /* Filename exclusion/inclusion patterns */ unsigned int fpatterns, fpattern_sz * Searching patterns */ unsigned int patterns, pattern_sz * Shortcut for matching all cases like empty regex */ * Flags passed to regcomp() and regexec() */ int cflags = REG_NOSUB * 2*/ "cannot read bzip2 compressed file", * Default messags to use when NLS is disabled or no catalogue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * documentation and/or other materials provided with the distribution. * notice, this list of conditions and the following disclaimer in the Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer. Redistributions of source code must retain the above copyright * modification, are permitted provided that the following conditions * Redistribution and use in source and binary forms, with or without * Copyright (C) 2008-2009 Gabor Kovesdan * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |