Split records.txt into multiple files containing 1000 lines each.
Use part- as the output filename prefix.
Which command is appropriate?
split -l N INPUT PREFIX divides input into N-line files and adds suffixes to the chosen prefix.
Detailed explanation
split -b 1000 records.txt part-Incorrect. -b 1000 splits by bytes, not lines.
split -l 1000 records.txt part-Correct. split -l 1000 records.txt part- creates 1000-line parts.
head -n 1000 records.txt part-Incorrect. head displays the first lines and does not create a set of output files.
cut -l 1000 records.txt part-Incorrect. cut has no -l option for line-based file splitting.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); seq 1 5 >"$tmp/in"; split -l 2 "$tmp/in" "$tmp/part-"; wc -l "$tmp"/part-*; rm -rf "$tmp"Expected result
2行、2行、1行の3ファイルKey points
- -l means lines
- -b means bytes
- The prefix names output parts
Notes
- Environment: GNU coreutils 9.x / 一時ファイル
- Use small, disposable text streams when testing filters.
- Locale, encoding, and GNU/POSIX implementation details can affect edge cases.
Foundation review
Place the operation
Line-based splitting preserves input order while distributing complete lines across files.
Check the side effect
Count generated files and lines in a temporary directory.