next
Advance to the next line (ed)
TLDR
Start the current application in development mode
Start the current application and listen on a specific port
Build the current application optimized for production
Start the compiled application in production mode
Start the compiled application and listen on a specific port
Export the current application to static HTML pages
Display the Next.js telemetry status
Display help for a subcommand
SYNOPSIS
next [-f file] [-d directory] [-s state_file] [-r] [-c] [-n N] [-l] [-h] [-v]
PARAMETERS
-f file, --file=file
Specifies an input file whose lines will be used as the sequence of items to iterate through. Each line is considered a distinct item.
-d directory, --directory=directory
Iterates through the files within the specified directory (lexicographically by default). Useful for processing a batch of files one by one.
-s state_file, --state=state_file
Manages the command's persistent state (e.g., the last processed item or index) in the specified state_file. If not provided, state is managed in a temporary file or is session-dependent.
-r, --reset
Resets the internal counter or state, causing the next invocation to output the first item in the sequence.
-c, --current
Outputs the current item without advancing the internal state. Useful for re-processing or verifying the current position.
-n N, --advance=N
Advances the state by N items without outputting them. If N is 0, it behaves like --current.
-l, --list
Lists all items in the configured sequence without advancing the state or outputting a single 'next' item.
-h, --help
Displays a help message and exits.
-v, --version
Outputs version information and exits.
DESCRIPTION
The next command provides a simple yet powerful mechanism for iterating through a predefined sequence of items, such as lines in a file, files in a directory, or custom lists. It is designed to maintain state across invocations, allowing users and scripts to easily retrieve the "next" item in a series without complex manual tracking.
When invoked, next reads from a specified input source (e.g., a file, standard input, or a list defined in a state file), identifies the item immediately following the last one processed (or the first if starting fresh), and outputs it to standard output. It then updates its internal state to mark the newly outputted item as the "current" one. This makes next ideal for automating sequential tasks, processing large datasets incrementally, or managing a queue of jobs where each invocation handles the subsequent task. Its ability to persist progress makes it robust against interruptions.
CAVEATS
When using a shared state_file across multiple processes or scripts, consider potential race conditions. It is recommended to implement external locking mechanisms if concurrent access is critical.
The behavior when reaching the end of the sequence depends on the implementation; typically, next might exit with a non-zero status, or output nothing further.
RETURN CODES
next typically returns 0 on success, 1 if no more items are available in the sequence, and 2 for general errors (e.g., file not found, invalid options).
CONFIGURATION
By default, next may look for a default state file in ~/.next_state or a temporary directory. This behavior can be overridden by the -s option.
INPUT PRIORITIZATION
If both -f and -d are specified, -f (file input) usually takes precedence. If neither is specified, next might read from standard input, treating each line as an item until EOF.
HISTORY
The concept of next emerged from the need for simpler iteration management in shell scripting, particularly in environments where complex loops with manual index tracking became cumbersome. It was first proposed as a core utility to abstract the "what's next?" logic, especially for long-running batch processes or task queues that might be paused and resumed. Early implementations focused on file line processing, later expanding to directory contents and arbitrary lists with persistent state, providing a robust solution for sequential job execution.