skip to content

Which JMeter CLI flag stops a nightly `-l results.jtl` run from appending to last night's rows?

level: middleimportance: should knowfreq 52%

answer

  1. Not a truncate; something stronger
  2. One letter, no argument
  3. It also clears the HTML report folder
  4. Otherwise the CSV is opened in append mode

basics

~20 s

The -f flag, long form --forceDeleteResultFile. It deletes existing results files and the web report folder before the test starts. Without it, JMeter opens an existing CSV results file in append mode and never rewrites the header.

solid answer

~40 s

`-f` (`--forceDeleteResultFile`) takes no argument. Before the engine starts, JMeter walks the cloned tree for every `ResultCollector` and deletes the file it names — the one `-l` created and any listener saved in the plan — throwing `Could not delete results file <path>` if a delete fails. The same flag also makes an existing `-o` report folder be emptied instead of rejected. Without `-f`, `ResultCollector.getFileWriter` sees that the CSV file exists, opens it in append mode and skips the header, so the second night's rows land underneath the first night's. For XML output it trims the closing `</testResults>` and continues the same document. The alternative is a distinct file name per run, but note that only `-j` expands a date pattern for you; `-l` does not.

code

bash · 5 lines
bash
# One fixed path, cleared before every run
jmeter -f -n -t plan.jmx -l results.jtl -j "nightly_'yyyyMMdd'.log"

# Or keep history by giving each run its own name (built outside JMeter)
jmeter -n -t plan.jmx -l "results-$(date +%Y%m%d).jtl" -j "nightly_'yyyyMMdd'.log"

go deeper

for a junior

Know that a second run does not start a clean results file, and that -f is the flag that makes it do so.

for a middle

Explain the append decision inside ResultCollector: the file exists, so the stream is opened in append mode and the header is skipped.

for a senior

Weigh -f against a per-run file name, and know that -f deletes every ResultCollector's file plus the report folder, not just the one -l named.

for a principal

Decide as a standard whether the team keeps one clearable path or an accumulating set of dated artefacts, and who consumes each.

## What JMeter does with an existing results file `-l results.jtl` builds a `ResultCollector` and opens the file through `ResultCollector.getFileWriter`. That method decides between append and truncate by looking at the file itself: - **CSV output** (the stock format): if the file already exists the stream is opened in append mode, and because JMeter knows the file is non-empty it also skips writing the column header again. Yesterday's rows stay, tonight's rows follow. - **XML output**: JMeter reads the tail of the file, trims the closing `</testResults>` terminator and continues writing inside the same document. Neither path warns you. Night after night the file grows, and any tool that reads the whole file is silently reading a union of runs. ## What `-f` does `-f`, long form `--forceDeleteResultFile`, takes no argument. The manual describes it as *"force delete existing results files and web report folder if present before starting the test"*, and that is exactly what happens: 1. During option parsing, `-f` sets an internal `deleteResultFile` flag. 2. Before the engine starts, JMeter walks the cloned test tree for every `ResultCollector` and deletes the file each one names — the `-l` collector **and** any listener saved in the plan. If a delete fails it throws `Could not delete results file <path>` and the run stops. 3. The same flag is handed to the report-folder check, so an existing `-o` folder is deleted recursively and recreated instead of being rejected as non-empty. So `-f` is broader than it looks: it is not "truncate the file `-l` names", it is "clear every results artefact this invocation is about to write". ## Fresh file versus fresh name There are two shapes for a nightly run and they are a real choice: | Approach | Line | What you get | |---|---|---| | One fixed path, cleared each night | `-l results.jtl -f` | A stable path anything downstream can hard-code; last night's rows are gone. | | A new path each night | `-l results-20260909.jtl` | Full history on disk; the path changes nightly, so whatever reads it must be told which one. | `-f` is not a truncate-in-place: it deletes the file. Anything that had the old file open, or that expected to find it, gets nothing. ## The date-pattern trick applies to `-j`, not `-l` JMeter can date-stamp exactly one file name for you. If the `-j` argument contains paired single quotes, the launcher treats the quoted text as a `DateTimeFormatter` pattern and substitutes the current time: - `-j "jmeter_'yyyyMMddHHmmss'.log"` becomes `jmeter_20260909020000.log`. - An unpaired quote is refused with `Invalid pairs of single-quotes in the file name`, and the raw name is used instead. The `-l` argument gets no such treatment. It is checked only for the special name `LAST`; a literal `'yyyyMMdd'` in a `-l` value stays literal, quotes and all. If you want a dated JTL name you have to build the string before JMeter sees it. ## Choosing - Use `-f` when downstream consumers want one predictable path and you do not keep history on the generator box. - Use a distinct name per run when you want the raw JTLs to accumulate, and accept that the path is now a variable. - Do not rely on "it will just overwrite" — that is the one thing JMeter does not do.

  • Does -f only delete the file named by -l?
    No. JMeter searches the cloned test tree for every ResultCollector and deletes each one's file, so a Simple Data Writer saved inside the .jmx loses its output too. It also empties the -o report folder. Treat -f as clearing every results artefact the invocation is about to write.
  • What happens if -f cannot delete the file?
    JMeter throws IllegalStateException with the message `Could not delete results file <absolute path>` plus the file's canRead and canWrite flags, and the run does not start. A file held open by another process, or one owned by a different user, is the usual cause.
  • Can you make the -l results file carry a timestamp the way -j can?
    Not from JMeter. The paired-single-quote date pattern is applied by the launcher to the -j run-log name only. The -l argument is inspected solely for the special name LAST, so a dated JTL name has to be assembled before the process starts.

saying these in an interview costs you the question

  • Assumes JMeter overwrites an existing results file by default
  • Thinks -f takes the file name as an argument
  • Believes -f only affects the file named by -l
  • Says the CSV header is rewritten on every run
  • Expects paired single quotes in -l to expand to a date