Before getting to the actual failure that you're having, there are few things you need to fix in your command to handle some corner cases
find "$directory" -maxdepth 1 -mindepth 1 -print0 | \
xargs -0 realpath | \
parallel -j 4 zip -r "$new_directory"/{/.}.zip {}
The changes in find are:
-mindepth 1 - this will exclude your top directory, so you won't need your grep -v command.
-print0 - This will solve a possible problem case any of you files include spaces or any escape characters. All the files will be delimited by the the null character instead of a new line.
That's why you also need to add the -0 to your xargs command, so it would read the input delimited by the null characters.
Further troubleshooting
In case it doesn't solve your issue, you'll need to debug it further.
First, remove the parallel command altogether and check if the input for this command looks as expected.
If it seems ok, add verbosity to the parallel command to capture exactly what it's doing:
parallel -t -j 4 zip -r ${new_directory}/{/.}.zip {} 2> parallel.log
- Then you'll have the list of commands it's running in the
parallel.log file. Check if the zip commands seem to be generated correctly.
- If you still don't see anything unusual at the list of
zip commands in the log file, try the commands in the file:
bash -x parallel.log
At some during the process you'll have to see at what stage you receive the error.
find "$(realpath "$directory")" -maxdepth 1 -mindepth 1. That wayrealpathis also only called once. – FelixJN Jul 05 '23 at 14:19