Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Avoiding Tar's (or Any Other Commandline's) Argument List Too Long Error

DZone's Guide to

Avoiding Tar's (or Any Other Commandline's) Argument List Too Long Error

·
Free Resource
When you try to tar a large number of files (cp, mv, or anything else) you may hit the limit of ARG_MAX. You can overcome this by generating a list of files then feeding it to tar as follows:


# generate the file list
find -iname '*.ext' > fileList.txt

#run tar passing it the file list
tar czvf archive.tar.gz --files-from fileList.txt

# a shorthand of this would be:
find . -name '*.ext' -print | tar -cvzf archive.tar.gz --files-from -
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}