/bin/tar: Argument list too long

If you find yourself stuck with over 30,000 files in a directory (text files in this example), packing them into a tar file can be tricky. You can get around it with this:

find . -name '*.txt' -print >/tmp/test.manifest
tar -cvzf textfiles.tar.gz --files-from /tmp/test.manifest
find . -name '*.txt' | xargs rm -v

Printed from: http://rackerhacker.com/2007/07/05/bintar-argument-list-too-long/ .
© Major Hayden 2012.

6 Comments   »

  • Dennis Quek says:

    What if I have a few directories and this adds up ?

    Should i tar all 10 directories as 10 tar files, then tar them together, or should I run find 10 times and combine the results into 1 txt tmp file. ?

    I should try them first... thanks

  • Hamlet says:

    Dennis Quek > I've that "find" will make the list of all the directories, recursively ! So the very useful commands shown here should work out-of-the-box...

    Thanks !

  • Calabacin says:

    3 years after this post was made, it still is VERY useful.

    It was for me at least, and I guess it has been for others, since it was #1 in Google for my query.

  • Maybe littl late, but another simple way to tar the full directory content with lot of files is doing this:
    Assuming you are in the directory of interest.

    "Bad" way:

    $ tar cfz bk_name.tar.gz *

    Alternative:

    $ tar cfz bk_name.tar.gz ./

    regards

  • Parimal says:

    Thanks for sharing this. It is very useful.

  • chewie says:

    THX --> what a beautiful work arround... :)
    regards
    chewie

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this