Operating System - HP-UX
1832494 Members
6039 Online
110043 Solutions
New Discussion

Re: Maximum number of files using tar

 
SOLVED
Go to solution
Sara Burchell
Occasional Contributor

Maximum number of files using tar

What is the maximum number of files I can tar at once? I have a directory with several thousand 1-line files that I would like to tar into one file. I attempt to do: tar cf tarfile.tar * and the error I get is ksh: /usr/bin/tar: arg list too long. I've also tried: tar cf tarfile.tar a* (to get all files starting with "a"), and receive the same error. Anyone know the most I can tar at once?
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Maximum number of files using tar

Hi Sara,

You are asking the wrong question. It is not a tar limit but rather a limit of the shell. The '*' is expanding to exceed argmax. All you need to do is:
cd to desired directory
tar cf /tmp/tarfile.tar .

That will get all the files in the directory.

Clay
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: Maximum number of files using tar

This is an important note about massively flat directories (ie, thousands of files in a single directory). The ls/ll commands will really slow down the system and any attempt to manipulate them with regular expressions (like mv *) will get the same error.

The reason is that the shell first processes the * character, then replaces it with the result on the command line--which is not unlimited in size. There is a patch that extends the maximum command line but it still isn't infinite, so:

1. Redesign the directory for a hierachy so there are only a few dozen files at each level or,

2. become very familiar with find and -exec, and also learn about xargs. You'll need it.


Bill Hassell, sysadmin