3

I am creating a tar and untar it at other location using:

$ tar -C sourcedir -cf - . | tar -C targetdir -xpf -

but it fails like this
Error I am getting is :Argument list too long - tar, when I am reducing the number of files I mean doing it in batches of files(like 1000 files at a time) it works.
Another point I noticed:
if file names are shorter than it works fine.

I am not sure what exactly is limiting this? please give suggestions.

  • Looks more like a unix than a programming question. Please also always give the complete error message you get. – Axel Jul 1 '15 at 11:31
  • Are you sure you are using that exact command and getting that exact message? Looks strange. – Basile Starynkevitch Jul 1 '15 at 14:12
  • My guess is that the first dot was actually a * – Basile Starynkevitch Jul 1 '15 at 14:21
6

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

| improve this answer | |
  • is there any way we can increase the limit for the argument list? – ritzz.soni Jul 1 '15 at 13:54
  • 2
    Don't do that. Just learn to use more wisely tar. – Basile Starynkevitch Jul 1 '15 at 13:57
  • sure thanks.. is this files-from and -T option also has any limitations? – ritzz.soni Jul 1 '15 at 14:10
  • 1
    Surely, limited by available resources. Nothing is infinite in this universe (except, and we are not sure, the universe itself). – Basile Starynkevitch Jul 1 '15 at 14:11
  • In addition, even in an infinite universe, you could not see all of it. Some we always have limitations. – Basile Starynkevitch Jul 1 '15 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.