bash error: argument list too long

March 12th, 2007 by Rohan

If you need to process a large number of files on the command line, you might get an error from bash (1), if the number of files are huge.

I needed to process around 13k HTML files, so my first move was to get all these files into a tar (1) file. The following command gives an error -

$ tar cf - *.html > all_html_files.tar
bash: /bin/tar: Argument list too long

One solution is to use find (1) in combination with xargs (1) as follows -

$ find . -name ‘*.html’ | xargs tar cf - > all_html_files.tar

Note the single quotes surrounding *.html. This goes directly to the find command without bash trying to expand the argument list.

More info is here.

[Post to Twitter] Tweet This Post  [Post to Facebook] Facebook 

Leave a Reply




Tweet This Post links powered by Tweet This v1.4.1, a WordPress plugin for Twitter.