0

I have to gunzip all the files in folder (say Folder A), which has multiple folder hierarchy with files in each of them. This Folder A is present in thousands of folders in a directory. I need to gunzip all the files in all the folders. I'm trying below command:

gunzip -r path/to/Folder/*/Folder_A/

and I get this error: Argument list to long.

Please help me with the command to gunzip the files.

0
for folder in path/to/Folder/*/Folder_A/; do gunzip -r "$folder"; done

I didn't test it, but this should do the trick. Bash is expanding path/to/Folder/*/Folder_A/ into the multiple directories so the command becomes gunzip -r path/to/Folder/1/Folder_A/ path/to/Folder/2/Folder_A/ path/to/Folder/3/Folder_A/ # and so on but gunzip apparently doesn't accept your “thousands” arguments. The loop from above expands the * first and creates a new gunzip-command for each of them.

if the for-loop is not working, you can try it with find:

find /path/to/Folder -name Folder_A -type d -print0 | \
    while read -d $'\0' folder; \
    do \
        gunzip -r "$folder" \
    done

(both solutions may not work, if the *-directories use special chars or spaces)

  • 3
    Please don't write something and then later contradict it. Fix your answer so it makes sense on the first reading. At the moment it reads like two separate authors having an argument – roaima Oct 26 '20 at 21:45
  • the first method with for loop worked, Thanks blaimi – Chakrakeerthi Reddy Oct 26 '20 at 22:36

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