This page is a quick reference for the Splunk command line interface (CLI): adding and removing data inputs, sending data to an index, setting up forwarding and receiving, checking configuration with btool, and cleaning or removing indexes. Below the original command list you will find corrected versions of a few commands, the order to run them in, ways to check the results, and fixes for common errors.
How to add monitor in Splunk?
$ sudo ./splunk [add|edit|remove|list] [monitor|exex|tcp|udp|oneshot]
source - file, directory, scripted input, or socket to manage
How to remove monitor?
$ sudo ./splunk remove monitor /var/log/jenkins
How to set hostname?
$ sudo ./splunk add monitor /var/log/dmesg -hostname rajesh -index newindex
$ sudo ./splunk add monitor /opt/lampp/etc -hostname rajhost -index rajesh
How to upload to new index?
$ sudo ./splunk add monitor /var/log/dmesg -hostname rajesh -index newindex
How to upload a file?
$ sudo ./splunk add oneshot /var/log/applog
$ sudo ./splunk add oneshot C:\Program Files\AppLog\log.txt
$ sudo ./splunk add forward-server <host>:<port> -auth <username>:<password>
Alternatively, if you have many forwarders, you can use an outputs.conf file to specify the receiver. For example:
[tcpout:my_indexers]
server= splunk_indexer.acme.com:9997
This command, <port> is the network port you want the receiver to listen on.
$ sudo ./splunk enable listen <port> -auth <username>:<password>
$ sudo ./splunk enable listen 9997 -auth <username>:<password>
This command below will also show which apps each setting is coming from.
$ sudo ./splunk cmd btool --debug inputs list
Permanently remove event data from an index by typing
$ splunk clean eventdata
$ splunk clean eventdata -index <index_name>
$ splunk stop
$ splunk clean eventdata # To permanently remove data from all indexes
$ splunk stop
$ splunk clean eventdata -index _internal -f # To permanently remove data from _internal
Remove all data from one or all indexes
$ splunk help clean
Remove an index entirely
$ splunk stop
$ splunk remove index main # cannot remove idx=main, is internal
$ splunk remove index <index_name>
Disable an index without removing it
$ splunk disable index <index_name>
Code language: HTML, XML (xml)
Before you run any Splunk CLI command
The splunk binary is in $SPLUNK_HOME/bin. The default location is /opt/splunk on a Splunk Enterprise server and /opt/splunkforwarder on a universal forwarder. The example above switches between ./splunk and splunk. Both work: ./splunk means you are in the bin directory, and plain splunk means that directory is on your PATH.
export SPLUNK_HOME=/opt/splunk # or /opt/splunkforwarder
export PATH=$SPLUNK_HOME/bin:$PATH
splunk status # is splunkd running?
splunk version
splunk login # authenticate once per sessionCode language: PHP (php)
Most commands that change configuration need splunkd to be running and need you to log in. If you run splunk login first, you don't have to add -auth <username>:<password> to every command, and your password stays out of your shell history.
Note: The example above starts every command with sudo. Splunk should run as a dedicated non-root user, usually splunk. If you run CLI commands as root, files under $SPLUNK_HOME can end up owned by root, and the service then fails to start as the splunk user. Use sudo -u splunk splunk <command> or switch to that user instead.
Corrected commands from the example above
Most of the original list is valid, but a few commands contain typos, run in the wrong order, or run on the wrong host. Here are the corrected versions:
# Generic syntax: input type is exec, not "exex"; oneshot only supports "add"
splunk [add|edit|remove|list] [monitor|exec|tcp|udp] <source> [options]
splunk add oneshot <file> [options]
# Create the index BEFORE sending data to it
splunk add index newindex
splunk add monitor /var/log/dmesg -hostname rajesh -index newindex -sourcetype dmesg
# Windows oneshot: no sudo, quote paths that contain spaces, run from %SPLUNK_HOME%\bin
.\splunk.exe add oneshot "C:\Program Files\AppLog\log.txt" -index main
# Clean event data: stop Splunk FIRST, then clean, then start
splunk stop
splunk clean eventdata -index <index_name> -f
splunk start
# Removing an index does not require a stop
splunk remove index <index_name>Code language: PHP (php)
exexis a typo forexec, the input type for scripted inputs.add monitor ... -index newindexdoes not create the index. If the index doesn't exist, the input is saved anyway, but events sent to the missing index are dropped and splunkd logs a warning. Create the index first withsplunk add index.sudodoes nothing on Windows, and an unquoted path with a space (C:\Program Files\...) gets split into two arguments.splunk clean eventdataonly works when Splunk is stopped. The example above runs it beforesplunk stop.splunk remove indexruns against a live instance, so you don't need thesplunk stopthat comes before it in the example above.splunk add forward-servergoes on the forwarder, not the indexer. It is a forwarding command, not a file-upload command, so it belongs in its own group.
Managing data inputs
monitor watches a file or directory continuously and indexes new data as it is written. oneshot indexes a file once and doesn't watch it afterwards, which is useful for historical logs or a quick test.
# Continuous monitoring with metadata
splunk add monitor /var/log/jenkins -index ci -sourcetype jenkins -hostname build01
# Inspect and edit
splunk list monitor
splunk edit monitor /var/log/jenkins -sourcetype jenkins:log
# Stop monitoring (data that is already indexed is NOT deleted)
splunk remove monitor /var/log/jenkins
# One-time upload
splunk add oneshot /var/log/applog -index main -sourcetype applog
# Network inputs
splunk add tcp 5514 -sourcetype syslog -index network
splunk add udp 514 -sourcetype syslog -index network
splunk list udpCode language: PHP (php)
The CLI writes these inputs to an inputs.conf file, usually in $SPLUNK_HOME/etc/apps/search/local/ or $SPLUNK_HOME/etc/system/local/, depending on the app context. On forwarders that you manage at scale, it's better to put inputs in an app and push it with a deployment server than to run CLI commands on each host.
Note: On Linux, ports below 1024 (such as UDP 514) need root privileges to bind. If Splunk runs as a non-root user, use a high port or put a syslog server in front of Splunk.
Setting up forwarding and receiving
Forwarding needs commands on both ends: the indexer listens, and the forwarder sends. Configure the receiver first.
- On the indexer, open a receiving port:
splunk enable listen 9997. - Make sure the host firewall allows inbound TCP 9997 from your forwarders.
- On the universal forwarder, point it at the indexer:
splunk add forward-server splunk_indexer.acme.com:9997. - On the forwarder, add an input:
splunk add monitor /var/log/messages -index os. - Check the connection:
splunk list forward-servershould show the indexer under active forwards.
The outputs.conf fragment in the example above has no default group, so a forwarder doesn't know to use it unless that is the only group defined. A complete minimal file, in $SPLUNK_HOME/etc/system/local/outputs.conf or in a deployment app, looks like this:
[tcpout]
defaultGroup = my_indexers
[tcpout:my_indexers]
server = splunk_indexer1.acme.com:9997, splunk_indexer2.acme.com:9997
If you list several servers, the forwarder load-balances automatically across them. Restart the forwarder after you edit the file by hand: splunk restart.
Checking configuration with btool
Splunk merges .conf files from many apps according to its precedence rules. btool shows the merged result. With --debug, it also shows which file each setting comes from, which is the quickest way to find out why an input or setting isn't doing what you expect.
splunk btool inputs list --debug
splunk btool outputs list tcpout --debug
splunk btool indexes list newindex --debug
splunk btool check # report typos and invalid stanzasCode language: PHP (php)
splunk cmd btool, as used in the example above, works too. splunk btool is the shorter form.
Index lifecycle commands
| Task | Command | Splunk state |
|---|---|---|
| Create an index | splunk add index <name> | Running |
| List indexes | splunk list index | Running |
| Disable (keep data) | splunk disable index <name> | Running |
| Re-enable | splunk enable index <name> | Running |
| Delete all events in one index | splunk clean eventdata -index <name> -f | Stopped |
| Delete events in all indexes | splunk clean eventdata -f | Stopped |
| Delete index and its config | splunk remove index <name> | Running |
| Help for clean options | splunk help clean | Either |
Note: clean eventdata and remove index permanently delete data, and you can't undo either one. Test on a non-production instance first. Never clean an index on a clustered indexer peer: indexer clusters manage buckets in their own way, and deleting data on one peer outside that process can leave the cluster inconsistent.
Before you remove an index, find every input that still sends to it (splunk btool inputs list --debug | grep <name>) and remove or repoint those inputs. Otherwise their events are dropped once the index is gone. The main index and internal indexes such as _internal can't be removed, but you can clean their event data.
Verifying that data arrives
After you add an input, confirm that events are indexed before you move on. You can search from the CLI:
splunk search 'index=newindex | head 5'
splunk search 'index=_internal source=*splunkd.log* log_level=WARN* | head 20'Code language: JavaScript (javascript)
The second search lists recent warnings from splunkd. Problems such as events going to a missing index, file permission errors and forwarder connection failures appear there.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Connection refused when you run a CLI command | splunkd is not running | splunk start, then retry |
| Monitor added but no events appear | Index does not exist, or the splunk user can't read the file | splunk add index <name>; grant read access, for example with setfacl -m u:splunk:r <file> |
| Old file content is not indexed again | The file is already recorded in the fishbucket, so Splunk treats it as seen | Use add oneshot for a one-time re-index |
| clean eventdata refuses to run | Splunk is still running | splunk stop first |
| Forwarder shows server as configured but inactive | Receiver is not listening, or a firewall blocks the port | splunk enable listen 9997 on the indexer; open TCP 9997 |
| Splunk fails to start after you used sudo | Files under $SPLUNK_HOME are now owned by root | chown -R splunk:splunk $SPLUNK_HOME |
Frequently asked questions
What is the difference between splunk add monitor and splunk add oneshot?
add monitor keeps watching a file or directory and indexes new lines as they are written. add oneshot indexes a file's current contents once and doesn't track it afterwards.
Does splunk add monitor create the index automatically?
No. The index named by -index must already exist. Create it with splunk add index <name>, otherwise events sent to it are dropped and splunkd logs a warning.
Do I need to stop Splunk to delete data from an index?
Yes, for splunk clean eventdata. Stop Splunk, run the clean, then start it again. splunk remove index runs while Splunk is up.
Where does the Splunk CLI save inputs I add?
In an inputs.conf file under $SPLUNK_HOME/etc, usually in the search app's or the system's local directory. Run splunk btool inputs list --debug to see the exact file.
How do I avoid typing -auth on every Splunk command?
Run splunk login once. The session stays authenticated for later commands, and your password stays out of your shell history.
Related tutorials
- Splunk Tutorials: Splunk Commands Reference
- What is Splunk and How it works? An Overview and Its Use Cases
- Top 50 Splunk interview questions and answers
- More Splunk tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals