Run several commands on find result with special characters in path

I want to generate the hash(es) of a file or folder, recursively, and store it onto a file. For performance reasons, want to skip the hash generation if file(s) already exist.

Command line:

./check.sh option checksums.md5 file_or_folder

Example code 1 inside script:

find "$3" -type f -print0 | xargs -0 -i sh -c "grep -Fq '{}' \"$2\" || md5sum '{}' >> \"$2\""

Example code 2:

find "$3" -type f -exec sh -c 'grep -Fq "echo $1 && $@" \"$2\" || md5sum "$@" >> \"$2\"' - {} +

The problem is, if in find path there are special characters, doesn't work. Example:

"$3"="movies/Joe's-[Grym].(@BTT)/Skidrow-$USER&.(@BK NET).MKV"

Could you help me fix it, with find or any other command?

1 Like

There's an older thread ask entitled, "How to escape all special characters?" that may help. If you send the output of your find through a similar SED processor, you'd end up with escaped special characters.

Cheers!

Keith

Would like to see an example. Can't get it to work.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.