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.

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.

  • 1
    Very nice one! :) – Vlad Tarniceru Dec 1 '13 at 15:26
  • is it bash programming ?? – Sukupa91 Dec 1 '13 at 15:29
  • 1
    @Sushantp606 yes brother – rɑːdʒɑ Dec 1 '13 at 15:30
  • 3
    It would be better to use for i in ~/sandbox/*; do zip -r "$i".zip "$i" && rm -rf "$i"; done -- that way the rm will only be executed if the zip succeeds, see here – evilsoup Dec 1 '13 at 19:45
  • 1
    Yes, thanks for all of the help. rajagenupual's first line worked well, but evilsoup's edit is also good to note. Thanks everyone! – sameetandpotatoes Dec 2 '13 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.