Argument list too long is not an error specific to tar
. It is an error (E2BIG
) of the execve(2) syscall (given by the kernel, which has to put some limitations on execve
to avoid spoiling memory). So your shell (which fork
-s then execve
-s the /bin/tar
program) tells you that error message.
It could be difficult to increase that limit (perhaps some sysconf
, I forgot the details). Or recompile your kernel and increase the ARG_MAX
in its include/uapi/linux/limits.h
.
GNU tar(1) accepts many interesting options (so please read the man page), in particular:
-T, --files-from=FILE
Get names to extract or create from FILE.
So collect the file paths to be archived in some (e.g. temporary) file, then pass it with -T
and you won't get any limitations.
However, the tar
command has many interesting features, and you can use them to have a reasonably sized command.
See also find(1) and xargs(1). Consider also dar or afio (as altenatives to tar
) or rsync
You might use GNU cp(1) as cp -va sourcedir destdir
*