Check the number of lines in a text file using the wc command, which stands for “word count”.
$ wc -l access.log
146330 access.log
We’re way over our limit. We’ll need to split this into 3 segments. We’ll use the split utility to do this.
$ split -l 60000 access.log $ ls -l
total 79124 -rw-rw-r– 1 root root 40465200 2006-09-19 12:00 access.log -rw-rw-r– 1 root root 16598163 2006-09-19 12:05 xaa -rw-rw-r– 1 root root 16596545 2006-09-19 12:05 xab -rw-rw-r– 1 root root 7270492 2006-09-19 12:05 xac
We’ve now split our text file into 3 separate files, each containing 60,000 lines or less. The last file contains the leftover amount. You can rename the individual chunks using the mv command.