title: How to split a large file into many small files using bash?
body: <p>I have a file, say <code>all</code>, with 2000 lines, and I hope it can be split into 4 small files with line number 1~500, 501~1000, 1001~1500, 1501~2000. </p>
  
  <p>Perhaps, I can do this using: </p>
  
  <pre><code>cat all | head -500 &gt;small1
  cat all | tail -1500 | head -500 &gt;small2
  cat all | tail -1000 | head -500 &gt;small3
  cat all | tail -500 &gt;small4
  </code></pre>
  
  <p>But this way involves the calculation of line number, which may cause error when the number of lines is not a good number, or when we want to split the file to too many small files (e.g.: file <code>all</code> with 3241 lines, and we want to split it into 7 files, each with 463 lines). </p>
  
  <p>Is there a better way to do this?</p>