4

Currently, I have this directory structure:

/Downloads
    /Download 1/
    /Download 2/
    /Download 3/
    ...

I would like to have this directory structure:

/Downloads
    Download 1.zip
    Download 2.zip
    Download 3.zip
    ...

Essentially, I want to zip Download 1 into Download 1.zip and then remove Download 1. What would be the fastest/easiest way to achieve this? I'm running Ubuntu 12.04.

The reason I'm asking is because this folder is shared on my local network. When people ask this on my Apache Web Server, I want them to download Download 1, so I need it to be a zip file.

sameetandpotatoes
  • 1,176
  • 12
  • 25

1 Answers1

6

try with command I have tried in the image , hope thats gonna help you.

enter image description here

For removing you just can add an extra line that

rm -rf $i

The total command can be as

 for i in ~/sandbox/*; do zip -r "$i".zip "$i"; rm -rf "$i"; done

The command which deletes Folders after verifying successful Zip creation.

for i in ~/sandbox/*; do zip -r "$i".zip "$i" && rm -rf "$i"; done

Thank you @evilsoup for noticing. hope that helps.

Raja G
  • 102,391
  • 106
  • 255
  • 328