Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Whats the easiest way to get around this?


share|improve this question
up vote 6 down vote accepted


find . -type f -exec gunzip {} +

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

share|improve this answer
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
find . -type f -iname "*.gz" -exec gunzip {} + to match only files that end .gz ignoring case. – richard Aug 23 '14 at 22:51
@richard: -iname is not POSIX. – cuonglm Aug 24 '14 at 4:53

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
share|improve this answer
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 at 14:56

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.

share|improve this answer
You can save the call to xarg by using the -exec {} + construct of find. – Michael 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 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

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.)

share|improve this answer

Simplest way I have found is:

gunzip -r .
share|improve this answer
You haven't even bothered reading the question, have you ? – don_crissti Jan 30 at 11:53
@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 at 12:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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