The Ultimate SPL Cheatsheet for Detection Engineers

Your interactive reference for Splunk Search Processing Language commands

Search commands, examples, or security use cases...

Find, copy, and learn essential Splunk commands for security monitoring and threat detection

Command Categories

All SPL Commands

This interactive cheatsheet contains the most essential SPL commands for detection engineers and security analysts. Each command includes syntax, description, practical examples, and security use cases. Use the search box to quickly find commands or browse by category.

This page is a work in progress so let us know if you have any suggestions or feedback! We aim to have this be all encompassing for SPL commands!

search

Basics

Syntax

search [search terms]

Description

The foundation of SPL queries, initiates a search with specified terms

Example

search index=windows EventCode=4624

Security Use Case

Search for successful authentication events in Windows logs

index

Basics

Syntax

index=[index_name]

Description

Specifies which index(es) to search in

Example

index=windows index=linux

Security Use Case

Target searches to specific data repositories

sourcetype

Basics

Syntax

sourcetype=[sourcetype]

Description

Filters events based on the data source type

Example

sourcetype=WinEventLog:Security

Security Use Case

Focus searches on specific log types

fields

Basics

Syntax

| fields [+/-] [field1], [field2], ...

Description

Keeps (+) or removes (-) specified fields from search results

Example

| fields + src_ip, dest_ip, user, action

Security Use Case

Focus on the most relevant security information and remove noise

table

Basics

Syntax

| table [field1], [field2], ...

Description

Displays results in a tabular format with specified fields

Example

| table _time, user, src_ip, action, status

Security Use Case

Create clean, readable output of security events for analysis or reporting

dnslookup

Basics

Syntax

| lookup dnslookup [ip_field] as [field_name] OUTPUT clienthost as [hostname_field]

Description

Performs DNS resolution on IP addresses in your search results

Example

| lookup dnslookup clientip as dest_ip OUTPUT clienthost as dest_host

Security Use Case

Enrich security alerts with hostname information for easier analysis

metadata

Basics

Syntax

| metadata type=[metadata_type] [index_name]

Description

Retrieves metadata about your Splunk environment, such as available sourcetypes in an index

Example

| metadata type=sourcetypes index=security

Security Use Case

Discover available data sources for security monitoring and threat hunting

where

Search & Filtering

Syntax

| where [condition]

Description

Filters results based on a specified condition

Example

| where user!="Administrator" AND action="failed"

Security Use Case

Filter out noise and focus on specific security conditions

regex

Search & Filtering

Syntax

| regex [field]="[pattern]"

Description

Filters results using regular expressions

Example

| regex user="(?i)admin.*"

Security Use Case

Find variations in usernames that might indicate suspicious activity

dedup

Search & Filtering

Syntax

| dedup [field1], [field2]

Description

Removes duplicate events based on specified fields

Example

| dedup src_ip, dest_ip, action

Security Use Case

Reduce alert noise by removing duplicate security events

rename

Search & Filtering

Syntax

| rename [oldname] AS [newname]

Description

Renames fields in search results

Example

| rename src_ip AS attacker_ip, dest_ip AS victim_ip

Security Use Case

Create more meaningful field names in security dashboards and reports

rex

Search & Filtering

Syntax

| rex field=[fieldname] "[regex pattern with named capturing groups]"

Description

Extracts fields using regular expressions

Example

| rex field=message "user=(?<username>[\w.]+)"

Security Use Case

Extract critical security information from unstructured log data

lookup

Search & Filtering

Syntax

| lookup [lookupname] [lookup-field] AS [event-field]

Description

Enriches events with data from lookup tables

Example

| lookup ip_classifications ip AS src_ip

Security Use Case

Add threat intelligence context to security events

Normalize Username

Search & Filtering

Syntax

| eval user=lower(if(match(user,".*\\\\.*"), replace(user,".*\\\\",""), user))

Description

Standardizes Windows username format by removing domain prefixes and converting to lowercase

Example

| eval user=lower(if(match(user,".*\\\\.*"), replace(user,".*\\\\",""), user))

Security Use Case

Normalize Windows usernames for consistent user tracking across different log sources

Remove Domain From Hostname

Search & Filtering

Syntax

| rex field=host "^(?<host>.*?)[\.\\|$]"

Description

Extracts just the hostname part without the domain suffix

Example

| rex field=dest "^(?<dest>.*?)[\.\\|$]"

Security Use Case

Standardize host identifiers for more consistent correlation across different log sources

Group By Subnet

Search & Filtering

Syntax

| rex field=ip "(?<subnet>\d+\.\d+\.\d+)\.\d+"

Description

Extracts the subnet portion (first 3 octets) of IP addresses

Example

| rex field=src_ip "(?<subnet>\d+\.\d+\.\d+)\.\d+" | stats count by subnet

Security Use Case

Identify network segments with suspicious activity for network-based detection

stats

Statistical

Syntax

| stats [function] BY [field]

Description

Generates statistics grouped by fields

Example

| stats count BY src_ip, dest_ip

Security Use Case

Identify top attackers or most targeted systems

rare

Statistical

Syntax

| rare [field]

Description

Shows statistically rare values, useful for anomaly detection

Example

| rare process

Security Use Case

Identify unusual processes that might indicate malware or attacks

eventstats

Statistical

Syntax

| eventstats [stats-function] AS [field]

Description

Calculates statistics and adds them to each event

Example

| eventstats count BY user AS user_event_count

Security Use Case

Add context to events by showing frequency compared to normal activity

top

Statistical

Syntax

| top [field]

Description

Shows the most common values of a field

Example

| top limit=20 src_ip

Security Use Case

Identify hosts generating the most security events or traffic

contingency

Statistical

Syntax

| contingency [field1] [field2]

Description

Displays a contingency table for two fields

Example

| contingency src_ip action

Security Use Case

Analyze relationships between attackers and attack methods

streamstats

Statistical

Syntax

| streamstats [stats-function] AS [field] BY [field]

Description

Computes running statistics on events in real-time order

Example

| streamstats count AS event_sequence BY src_ip

Security Use Case

Track progression of attack sequences in chronological order

Event Frequency Analysis

Statistical

Syntax

| stats count by [field] | eval events_perDay = round(count / [days],2)

Description

Calculates the frequency of events over different time periods

Example

| stats count by signature | eval days = 10 | eval events_perDay = round(count / days,2) | eval events_perWeek = round(count / (days / 7),2)

Security Use Case

Establish baselines for alert frequencies to identify unusual activity spikes

Field Summary with Coverage

Statistical

Syntax

| fieldsummary | eventstats max(count) as total | eval event_coverage = round(((count / total)*100),2)."%"

Description

Provides a summary of fields with percentage of events containing each field

Example

index=firewall sourcetype="pan:traffic" | fieldsummary | eventstats max(count) as total | eval event_coverage = round(((count / total)*100),2)."%"

Security Use Case

Identify which security-relevant fields are consistently populated for reliable detection

earliest

Time-based

Syntax

earliest=[time_modifier]

Description

Sets the earliest time boundary for the search

Example

earliest=-24h

Security Use Case

Limit searches to relevant timeframes during incident response

latest

Time-based

Syntax

latest=[time_modifier]

Description

Sets the latest time boundary for the search

Example

latest=now

Security Use Case

Create time-bounded searches for specific security incidents

bucket

Time-based

Syntax

| bucket _time span=[time_unit]

Description

Groups events into time buckets for time-series analysis

Example

| bucket _time span=5m

Security Use Case

Analyze attack patterns over specific time intervals

localize

Time-based

Syntax

| localize

Description

Converts UTC timestamps to the local timezone

Example

index=windows | localize

Security Use Case

Align security events with local business hours to identify suspicious after-hours activity

sistats

Time-based

Syntax

| sistats count BY [field1] span=[time_period]

Description

Computes statistics while maintaining chronological information

Example

| sistats count BY src_ip span=5m

Security Use Case

Identify burst patterns in attack traffic

First/Last Seen Analysis

Time-based

Syntax

| stats earliest(_time) as firstTime latest(_time) as lastTime by [field]

Description

Finds the first and last occurrence of each unique value for a field

Example

| stats earliest(_time) as firstTime latest(_time) as lastTime by dest | eval firstTime=strftime(firstTime,"%Y-%m-%d %H:%M:%S") | eval lastTime=strftime(lastTime,"%Y-%m-%d %H:%M:%S")

Security Use Case

Identify when hosts or attackers first appeared in your environment and when they were last active

Inactive Assets Detection

Time-based

Syntax

| stats latest(_time) as lastTime by host | where lastTime < relative_time(now(),"-[timeframe]")

Description

Identifies assets that have not sent logs within a specified timeframe

Example

| stats latest(_time) as lastTime earliest(_time) as firstTime by host | eval recent = if(lastTime > relative_time(now(),"-30d"),1,0) | where recent=0

Security Use Case

Detect compromised or decommissioned assets that should be sending logs but are not

Relative Time Reference

Time-based

Syntax

| eval [fieldname]=relative_time(now(), "[time_modifier]")

Description

Creates a timestamp relative to the current time, useful for comparing against event times

Example

| eval yesterday=relative_time(now(), "-1d@d")

Security Use Case

Create dynamic time windows for baselining and anomaly detection

transaction

Detection-specific

Syntax

| transaction [fields] maxspan=[time]

Description

Groups related events into transactions based on fields and time windows

Example

| transaction src_ip, dest_ip maxspan=5m

Security Use Case

Track attack sequences and multi-stage attacks

anomalousvalue

Detection-specific

Syntax

| anomalousvalue action=filter [field]

Description

Detects statistical outliers in field values

Example

| anomalousvalue action=filter pct(failed_logins)

Security Use Case

Identify potential brute force attacks based on unusual login failure rates

diff

Detection-specific

Syntax

| diff [field]

Description

Shows differences between consecutive events

Example

| diff process_list

Security Use Case

Identify changes in system state that might indicate compromise

cluster

Detection-specific

Syntax

| cluster [field] showcount=true

Description

Groups similar events using field similarity

Example

| cluster message showcount=true

Security Use Case

Group similar attack patterns or error messages to identify attack campaigns

multisearch

Detection-specific

Syntax

| multisearch [search1] [search2]

Description

Runs multiple searches and combines the results

Example

| multisearch [search index=windows EventCode=4625] [search index=firewall action=blocked]

Security Use Case

Correlate failed login attempts with firewall blocks for comprehensive threat detection

predict

Detection-specific

Syntax

| predict [field]

Description

Uses statistical forecasting on time series data

Example

| timechart count by src_ip | predict count

Security Use Case

Detect anomalies by comparing actual vs. predicted event patterns

CPE Extraction

Detection-specific

Syntax

| eval vendor = mvindex(split(cpe,":"),[index])

Description

Extracts vendor, product and version information from CPE strings for software inventory

Example

| eval cpe_parts = split(cpe,":") | eval vendor = mvindex(cpe_parts,2) | eval product = mvindex(cpe_parts,3) | eval version = mvindex(cpe_parts,4)

Security Use Case

Extract software details from CPE data to identify vulnerable software versions

timechart

Visualization

Syntax

| timechart count BY [field]

Description

Creates a time-series chart of events

Example

| timechart count BY src_ip

Security Use Case

Visualize attack patterns and trends over time

geostats

Visualization

Syntax

| geostats count BY [field]

Description

Creates geographic visualizations

Example

| geostats count BY src_ip

Security Use Case

Map attack origins and geographic attack patterns

chart

Visualization

Syntax

| chart [stats-function] OVER [field] BY [field]

Description

Creates a chart with multiple dimensions

Example

| chart count OVER dest_port BY src_ip

Security Use Case

Visualize attack targets by attacker across different services/ports

trendline

Visualization

Syntax

| timechart count | trendline [field]

Description

Adds trend lines to time-series visualizations

Example

| timechart count | trendline sma5(count)

Security Use Case

Identify long-term security event trends and anomalies

Sankey Diagram

Visualization

Syntax

| table [field1] [field2] | appendpipe [stats count by [field1] [field2] | rename [field1] as source, [field2] as target]

Description

Creates data for Sankey diagrams to visualize complex relationships

Example

| table src_ip dest_port dest_ip | appendpipe [stats count by src_ip dest_port | rename src_ip as source, dest_port as target] | appendpipe [stats count by dest_port dest_ip | rename dest_port as source, dest_ip as target] | search source=* | fields source target count

Security Use Case

Visualize attack paths and lateral movement through your network

datamodel

Advanced

Syntax

| datamodel [datamodel_name] [nodename] search

Description

Searches accelerated data models

Example

| datamodel Authentication Failed_Authentication search

Security Use Case

Perform fast searches on normalized security data

tstats

Advanced

Syntax

| tstats [function] from datamodel=[model] where [conditions]

Description

Fast statistics from data model acceleration

Example

| tstats count from datamodel=Network_Traffic where sourcetype=firewall

Security Use Case

Quickly analyze large volumes of security telemetry

map

Advanced

Syntax

| map [search]

Description

Runs a subsearch against each result

Example

| map search="search index=windows host=$host$ | stats count by EventCode"

Security Use Case

Enrich alerts with additional context from related logs

mcollect

Advanced

Syntax

| mcollect [index=name] [options]

Description

Saves search results to a specified index

Example

| mcollect index=detected_threats

Security Use Case

Create curated datasets of detected threats for further analysis

join

Advanced

Syntax

| join [field] [search]

Description

Joins the results of the current search with another search

Example

| join src_ip [search index=threats | fields ip, threat_intel]

Security Use Case

Enrich security events with threat intelligence from a separate dataset

savedsearch

Advanced

Syntax

| savedsearch [savedsearch_name]

Description

Runs a previously saved search within the current search

Example

| savedsearch "Known Malicious IPs"

Security Use Case

Incorporate standard threat detection logic into multiple searches

inputlookup

Advanced

Syntax

| inputlookup [lookup_file]

Description

Loads a lookup table as search results

Example

| inputlookup threat_intel.csv | search category="C2"

Security Use Case

Use static threat intelligence lists for detection and enrichment

outputlookup

Advanced

Syntax

| outputlookup [lookup_file]

Description

Saves search results to a lookup table

Example

| stats count by src_ip | where count>100 | outputlookup suspicious_ips.csv

Security Use Case

Create dynamic watchlists based on detected suspicious behavior

foreach

Advanced

Syntax

| foreach "*" [eval <<FIELD>>=...

Description

Applies an operation to all fields or specified fields

Example

| foreach "*" [eval <<FIELD>>=lower('<<FIELD>>') ]

Security Use Case

Normalize all field values for case-insensitive analysis and correlation

Current User Context

Advanced

Syntax

| rest /services/authentication/current-context

Description

Shows information about the current Splunk user context

Example

| rest /services/authentication/current-context splunk_server=local

Security Use Case

Verify user identity and permissions during security investigations

Multivalued Field to CSV

Advanced

Syntax

| eval [new_field] = mvjoin([mv_field],", ")

Description

Converts a multivalued field into a comma-separated string

Example

| fields mv_field | eval mv_field_csv = mvjoin(mv_field,", ")

Security Use Case

Format multivalued fields like destination IPs or hostnames for reports and exports

Ready to Practice Your SPL Skills?

Put your detection engineering knowledge into action with hands-on SPL problems and challenges.