Split events.log into files containing 100 lines each.
Use chunk- as the output filename prefix.
Which command is appropriate?
split -l sets the number of lines per output file. The final argument is the prefix for generated files.
Detailed explanation
split -b 100 events.log chunk-Incorrect. -b 100 splits by 100-byte blocks, not 100 lines.
Incorrect. -b 100 splits by 100-byte blocks, not 100 lines.
head -n 100 events.log > chunk-Incorrect. This writes only one prefix of the file and does not split the full input.
Incorrect. This writes only one prefix of the file and does not split the full input.
split -l 100 events.log chunk-Correct. -l 100 creates chunks of up to 100 lines with the chunk- prefix.
Correct. -l 100 creates chunks of up to 100 lines with the chunk- prefix.
split -n 100 events.log chunk-Incorrect. -n specifies a number of chunks rather than lines per file.
Incorrect. -n specifies a number of chunks rather than lines per file.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
seq 1 205 | split -l 100 - "$LAB_DIR/chunk-"
wc -l "$LAB_DIR"/chunk-*
rm -r "$LAB_DIR"Expected result
100 chunk-aa
100 chunk-ab
5 chunk-ac
205 total
※実際の表示には一時ディレクトリのパスが付くKey points
- -l selects a line count
- -b selects bytes instead
- The default suffix starts at aa
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.