Bash zip all files in directory one by one in individual zips

If you like me have for example folder filled with NES rom files that end with .nes extension and you would like to zip them all up in individual files to save some space.

I use this one-liner to zip all my NES collection so that it will take less space on my USB stick when I transfer it to my bartop arcade running RetroPie:

for file in *.nes ; do zip "$" "$file"; done

Even cooler way to do this in one line even if your .nes files are scattered in subfolders:

find ./ -iname "*.nes" -print0 | xargs -0 -I{} zip {}.zip {}

All your .nes files will be found from current folder and all sub-folders and zipped in one-by-one file in current folder.

I keep forgetting these one-liners and I need to find and adapt them over and over. That is why this time I wrote them down in my blog to have and to share.

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.