in such a filesystem structure:root/    |    container1/    |         |    |         subdir2/    |                |    |                subdir3/    |                       |    |                       subdir4/    |                              |    |                              file1    |                              file2    |                              subdir5/    container2/              |...I need to zip everything:under `/subdir4/``without the /subdir4/ itselfin all potential /container/ subdirs of the root/directoryname the zip the same as the parent folder of the contents being zipped (in this case, it would be subdir4.zip)Please bear in mind:these are not the real names of dirs and subdirs, it's just an approximation   I am using ZSH on a Mac OSXI am quite new to Unix/Linux scriptingI would really like a shell-agnostic, simple, loop kind of solution so I can learn as much as possible and be flexible in modifying this solution for other potential cases.Here is what I have tried so far, as suggested by friends:find . -mindepth 5 -maxdepth 5 -type d -exec sh -c 'pushd $0/..;zip -rFS $(basename $0).zip $(basename $0);popd ' {} \;In the meantime, I have learned that this solution has the following drawbacks:$0 should not be used as positional parameter because it is used in error reporting and/or as the shell script name (in my case, it's just a string)basename and dirname are best avoided if using bash (read more here)this syntax, with ... {} \;invokes as many shells as there are results, supposedly not efficient way of doing this type of operationI should have been using:$1 in my positional parameters... ;popd ' sh {} +That one is supposed to get all the results in a sort-of an array/list and apply the commands within the string passed to the sh all at once.Thanks!BONUS POINTS: :)can I name the resulting .zip same as /subdir3/ instead of as /subdir4/ from this hierarchy?
How to zip many n-th level subdirectories, without their top (parent) dir?
shell;find;zip;pushd