0

I'm using WSL (Ubuntu) and trying to recursively zip the files in a bunch of subfolders.

i.e.

Main Folder .
  SubFolder 1's files get zipped into a .zip
  SubFolder 2's files get zipped into a .zip
  SubFolder 3's files get zipped into a .zip
  SubFolder 4's files get zipped into a .zip
  SubFolder 5's files get zipped into a .zip

etc.

I nav to the Main Folder, and run this:

find . -type d -maxdepth 1 -execdir zip -r '{}.zip' '{}' \;

Upon doing so, I get spammed with a bunch of:

find: ‘zip’: No such file or directory

I've also tried the exact same line, using exec instead of execdir but got the same result. Anyone able to point out the problem?

0

1 Answer 1

2

that error means you have not installed the zip command, test with command -v zip; empty output means that is not installed, install sudo apt install zip.


to zip every directory's files individually excluding the directories you will need add -j option to the zip commnad:

find . -mindepth 1 -maxdepth 1 -type d -execdir zip -jr '{}.zip' '{}' \;

note that you need -maxdepth option to specify before -type d, also added -mindepth 1 to ignore zipping current directory; or replace both with [! -name . -prune; Limit POSIX find to specific depth?], so the command would be:

find . ! -name . -prune -type d -execdir zip -jr '{}.zip' '{}' \;

Alternatively you can use for-loop too:

for thing in ./*; do
    [[ -d "${thing}" ]] && zip -jr "${thing}.zip" "${thing}";
done

Note that due to use of -j option in case there were files with similar name collecting from different subdirectories into single zip file, command will stop zipping because of same files names.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .