0

I found that a great way to zip folders into their own zip files is through this loop:

for i in */; do zip -r "${i%/}.zip" "$i"; done

But I wanted to do this all in the background (e.g., nohup &), but I cannot get it to work. How do I do this?

1
  • replace zip -r "${i%/}.zip" "$i"; with nohup zip -r "${i%/}.zip" "$i" & - note in particular there is no semicolon after the & Commented Nov 10, 2019 at 2:01

2 Answers 2

0

You could execute your commands as a shell script, e.g.

nohup sh -c 'for i in */; do zip -r "${i%/}.zip" "$i"; done' &
3
  • This does all the zips sequentially (albeit in the background). My reading of the question was to do them all in parallel. Commented Nov 10, 2019 at 2:37
  • Yes, nothing fancy here, just "Make the for-loop work with nohup". Commented Nov 10, 2019 at 2:50
  • Oh actually in parallel is not necessary as sequentially definitely works. Thanks so much this worked!!! Commented Nov 10, 2019 at 3:08
0

The request is to do the compression in parallel.

nohup sh -c 'for i in */; do zip -r "${i%/}.zip" "$i" & done' &

This will start one zip for each subdirectory. These jobs are started under a common nohup, which is itself backgrounded.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.