Linux – tar specific number of file

bashlinuxtar

I have a directory with 27K files, I would like to tar them into multiple INDEPENDENT tar files, each will have 5000 files and the last one, will obviously have 2K (27K is not dividable by 5).

What is the fastest/easiest way to do this?

Best Answer

First create files with the filenames for each archive:

find <directory> | split -l 5000 - files.

Then create the tars:

for f in files.*; do tar -cf $f.tar --files-from $f; done

Untested but the basic idea should work.