Search code examples
linuxshellzipdirectory

Zip folders in folders in Linux shell


I don't know how to title this topic, but all I need to know if there is a way how to zip all folders inside one other folder.

This is my path:

/foldername/01/foldername2
/foldername/02/foldername2

I was hoping if there was something like this:

zip -r /tmp/my.zip /foldername/*/foldername2

Is this somehow possible?


Solution

  • You may get a list of nested foldername2 with find like this:

    $ find /foldername -type d -a -name foldername2
    

    and pass this list to zip:

    $ zip -r /tmp/my.zip $(find /foldername -type d -a -name flodername2)