grep(3)
[Home]
[Commands]
[Variables]
[Macro-Dev]
[Glossary]
NAME
SYNOPSIS
grep "[grep-options] <search-pattern> [file-mask] [file-mask ...]" ["starting-path"]
grep-for-region [search-pattern]
DESCRIPTION
grep performs a search for a pattern and displays all lines that contain that pattern within files in the current directory (or from starting-path) using built in MicroEmacs constructs rather than relying on any external executables such as grep(1). grep operates in exactly the same way as a traditional grep command line utility and uses a command line option sequence from the MicroEmacs command line. The grep-options allow recursive and regular expression searches, searching against the file modification time etc. The command line takes the user supplied grep-options, search-pattern, file-mask and starting-path. The output of the command is piped into the *grep* buffer.
grep-options
Defines the options that are specified on the command line, the default options may also be defined with the
find-setup(3) command invoked from the command line or from the the Tools menu. The grep-options are defined as follows:
--
Last option, the following string must be the search-pattern which may start with a '-'.
-a
Re-read all out of date buffers, prevents a manual prompt, equivalent of Yes to all. This is the inverse of -o
-b
-B
Do not ignore binary files.
-c
Command return the number of matchs found rather than the default, which is simply 0 for one or more matches or 1 if no matches were found.
-C
Command returns 0 (non-error for command-line tool) regardless of if it finds any matches.
-d
List directories or grep in directory listings.
-D
Do not list directories or grep in directory listings.
-e
Only include the matching string in the *grep* output buffer.
-f
-F
Do not list/search files.
-g
File masks are regex (i.e. .*.emf)
-G
File masks are not regex (i.e. *.emf)
-i
Ignore search pattern case (case insensitive).
-I
Do not ignore search pattern case (case sensitive).
-l
Use existing buffer of loaded files.
-L
Do not use existing buffer of loaded files.
-m
Search pattern is a regular expression.
-M
Search pattern is not a regular expression.
-o
Do not re-read all out of date buffers, prevents a manual prompt, equivalent of No to all. This is the inverse of -a.
-p
-P
Starting path not specified
-q
Enables quiet mode for reduced print-out.
-r
Recurse into sub-directories
-R
Do not recurse into sub-directories
-S <size>
File size - less than or equal, the following size formats are supported:
-S <number> File size specified bytes.
-S <number>k File size specified in Kilobytes.
-s <size>
File size greater than; supported size formats are the same as -S.
-T <time>
Modification time - older than, the following time formats are supported:
-T yy-mm-dd
-T yyyy-mm-dd
-T yyyy-mm-dd hh:mm:ss
-T days Offset time in days from midnight this morning, e.g. -T 0 would match all files not modified today.
-T days.hours[.minutes[.seconds]] Offset time in , e.g. -T 1.1.30 matches all files 25 hours and 30 minutes old.
Note that -T 1 is not the same as -T 1.0, except at midnight.
-t <time>
Modification time - newer than or equal, supported time formats are the same as -T.
-u
Removes the default file size limit of 100MB allowing files of any size to be search. Note that MicroEmacs uses
page-file(3) on files larger than 100MB to avoid using too much memory.
-U
Enforces the 100MB file size limit.
-x
-X
-&
Launch grep using a separate process, this stops the current MicroEmacs hanging during the grep process which can be useful for time consuming searches.
search-pattern
The search pattern to look for.
file-mask
The files to search for e.g. *.txt, if no file mask is given then grep attempts to get a file list from the current buffer, this could either be a *grep* output buffer, in which case each file listed will be selected for the next grep, or some kind of file listing (this could be a loaded directory, an output from find or a source revision control system such as cvs or svn) in which case the files to be searched must be selected (line starts with a "*".
starting-path
The directory location where the search should commence when the -p option is used. The default when -p is omitted is the location of the current buffer.
grep sets
$result(5) to the return of the command, which is 0 if matches were found or 1 of no match was found, unless options -c or -C are used.
grep-for-region uses the grep command to search for the string defined by the current region within all files of the current directory. If no region is defined within the current buffer the the string is prompted for.
find-setup invokes a dialogue and allows the default file-options to be specified when the find command is invoked.
NOTES
- Trying to make the command-line look like the standard UNIX grep(1) command may be more of a hindrance than a help because its not grep. No support is provided for options like -w, -l etc.
- The default when no options are given is -XGPRDfMIBL, default options may be set via the
find-setup(3) command (sets the /history/grep-com registry entry).
- Use of -d searches for <search-pattern> within the MicroEmacs directory listing.
- It may be advantageous to enable the -l option default using
find-setup(3).
The other options of the underlying
find(3) command are allowed but provide no benefit to these commands.
SEE ALSO
(c) Copyright JASSPA 2025
Last Modified: 2025/05/23
Generated On: 2025/09/29