Created on 05-11-2010 06:57 AM Edited on 11-29-2023 09:45 PM By Anthony_E
Description
This article describes how to use the 'grep' command in the CLI of a FortiGate system.
Scope
FortiOS firmware version 4.0 MR2, version 4.0 MR3, version 5.0.x, version 6.0.x, 6.2.x and 6.4.x, version 7.0.x, 7.2.x and 7.4.x.
Solution
The 'grep' command is applied as a standard command filter within the FortiOS firmware, with the following syntax:
show <subcommand> | grep <expression>
diagnose <subcommand> | grep <expression>
Example:
show system interface | grep https
set allowaccess ping https ssh http telnet
On the other hand, the option -invfcABC can be used to further filter out the output.
grep: option requires an argument -- 'A'
Usage: grep [-invfcABC] PATTERN
Options:
-i Ignore case distinctions
-n Print line number with output lines
-v Select non-matching lines
-f Print fortinet config context
-c Only print count of matching lines
-A Print NUM lines of trailing context
-B Print NUM lines of leading context
-C Print NUM lines of output context
On new firmware versions as 7.x, new grep options were added. Here is the output collected from a FGT running 7.0.12
Usage: grep [-ilHhnqvscABC] PATTERN [FILE...]
Options:
-i Ignore case distinctions
-l List names of files that match
-H Prefix output lines with filename where match was found
-h Suppress the prefixing filename on output
-n Print line number with output lines
-q Quiet
-v Select non-matching lines
-s Suppress file open/read error messages
-c Only print count of matching lines
-A Print NUM lines of trailing context
-B Print NUM lines of leading context
-C Print NUM lines of output context
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2024 Fortinet, Inc. All Rights Reserved.