Overview
seq prints a sequence of numbers to standard output, one per line. By default, it starts from 1, increments by 1, and generates numbers up to the specified end value. You can precisely control the sequence by specifying the start, increment, and end values as arguments.
Key Features
- Generates a sequence of numbers within a specified range.
- Allows customization of start, increment, and end values.
- Controls output delimiters and formatting.
- Useful for shell scripting and automation tasks.
Key Options
The seq command provides several useful options to control the sequence generation and output format.
Output Formatting
Generated command:
Try combining the commands.
Description:
`seq` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Examples demonstrating various ways to use the seq command.
Basic Usage (1 to 5)
seq 5
Outputs numbers from 1 to 5, one per line.
Specify Start and End (3 to 7)
seq 3 7
Specifies the start and end values to output numbers from 3 to 7.
Specify Increment (1 to 10, step 2)
seq 1 2 10
Specifies the start, increment, and end values to output numbers from 1 to 10, increasing by 2.
Output with Comma Delimiter
seq -s "," 1 5
Uses the -s option to output numbers separated by commas on a single line.
Output with Equal Width and Leading Zeros
seq -w 5
Uses the -w option to pad numbers with leading zeros to match the width of the longest number.
Output with printf-style Formatting
seq -f "file_%03g.txt" 1 3
Uses the -f option and printf-style formatting to output each number in a format like 'file_001.txt'.
Generate Floating-Point Sequence
seq 0.5 0.1 1.0
You can generate sequences using floating-point values.
Tips & Notes
Tips and notes for using the seq command more effectively.
Usage Tips
- Use with `for` loops: `for i in $(seq 1 5); do echo "Current number: $i"; done`
- Use with `xargs`: `seq 1 3 | xargs -I {} touch file_{}.txt` (creates file_1.txt, file_2.txt, file_3.txt)
- Useful for automating file or directory name generation.
- Can be used to control loop counts within scripts.
Notes
seq is part of GNU coreutils and is typically pre-installed on most Linux distributions. However, on some minimal installations or other Unix-like systems, you might need to use alternative commands like `jot`.