I have a folder with 36,348 files gz files. I want to unzip all of them.


gunzip ./*

results in

-bash: /usr/bin/gunzip: Argument list too long

What's the easiest way to get around this?



find . -type f -exec gunzip {} +

This assumes that current directory only contains files that you want to unzip.

  • Is there any version of find where find . doesn't work? – Patrick Aug 23 '14 at 19:38
  • @Patrick: I don't remember ./filename can work with gunzip. I have tried and it works. Roll back! – cuonglm Aug 23 '14 at 19:40
  • 3
    find . -type f -iname "*.gz" -exec gunzip {} + to match only files that end .gz ignoring case. – ctrl-alt-delor Aug 23 '14 at 22:51
  • 1
    @richard: -iname is not POSIX. – cuonglm Aug 24 '14 at 4:53
  • @richard, for POSIX portability, use find . -type f -name '*.[gG][zZ]' -exec gunzip {} + – Wildcard Nov 8 '16 at 12:33

The limit is in the kernel and is on the cumulative size of the arguments and environment passed to the execve() system call used to execute a command. You can split it in several invocations.

To gunzip all the .gz files in the current directory:

with zsh:

autoload zargs # best in ~/.zshrc
zargs ./*.gz -- gunzip

With ksh93:

command -x gunzip ./*.gz


printf '%s\0' *.gz | xargs -r0 gunzip

POSIXly (and with gunzip):

find . ! -name . -prune -name '*.gz' -exec gunzip {} +

(beware that one will also uncompress the hidden .gz files)

Or you can raise that limit on some systems. On recent versions of Linux:

ulimit -s unlimited
gunzip ./*.gz
  • Why we need -r in GNUly? – cuonglm Aug 23 '14 at 19:52
  • @Gnouc, not needed strictly speaking, except with nullglob. But doesn't harm and it's a good habit to have to use it unless you have a good reason not to. – Stéphane Chazelas Aug 23 '14 at 19:54
  • +1 for explaining why gunzuip *.gz did not work. – Hennes Jan 30 '16 at 14:56

Simplest way I have found is:

gunzip -r .
  • @don_crissti what is the problem, gunzip -r nicely has the expansion done by the gunzip circumventing the bash error. It of course also decompresses any files in subdirs, but since the OP used ./* subdirs would have led to problems if there were any. – Anthon Jan 30 '16 at 12:02

A bit efficient solution would be,

find $PWD -type f -name "*.gz" -print0 | xargs -0 gunzip

But if your find does not have -print0 option and your files/dir does not have space in naming, then you can skip -print0 and -0 arguments.

  • You can save the call to xarg by using the -exec {} + construct of find. – Michael Le Barbier Grünewald Aug 24 '14 at 8:40
  • Yes, but doing exec on every file would take more time, wouldn't it ? I guess usings xargs would be more efficient. – vknha Aug 24 '14 at 18:18
  • It will not exec the program once for each file, but rather behave much like xargs does, this is what the + at the end of the line is for. – Michael Le Barbier Grünewald Aug 24 '14 at 20:21
  • @MichaelGrünewald okay got it, I was not aware of + option. thanks. – vknha Aug 25 '14 at 7:41
  • If your find does not have -print0, then upgrade it. – ctrl-alt-delor Nov 8 '16 at 19:20

A less efficient ( but long-run very flexible ) process is make a batch file:

ls | grep .gz | sed -e 's/^/gunzip /' | less

shows you what will happen so a simple typo doesn't annihilate your system

ls | grep .gz | sed -e 's/^/gunzip /' | bash

does it right now

ls | grep .gz | sed -e 's/^/gunzip /' > unpack
at 02:00
bash unpack

does it overnight

(note this example does not account for spaces in filenames.)

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.