Zip individual files by extension in separate zip file with the same filename and zip extension

for z in *.txt; do zip "${z%".txt"}.zip" "$z"; done

Where “txt” can be replaced by any other extension, so file1.txt will be zipped to file1.zip, file2.txt will be file2.zip etc.

And to unzip all the files you can use the following:

for z in *.zip; do unzip "$z"; done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.