I want to find files and save the file name to a variable and use this variable in -exec in order to do some calculations with it
so for example every time the find returns a file name I use that file name in -exec in order to produce something else at the same time find command finds this file
thanks
Then don’t exec.
This is not robust with file names containing special characters, though.
Edit: If you want to do multiple things to the hits returned by
find, this is certainly possible withfind -execorxargsas well:Or you can mangle the output into a shell script and feed it to
sh:But if you really, truly want the action to happen as soon as
findlearns about the file,-execis probably the way to go. (I’m not clear on under what circumstances this would be a useful requirement. Perhaps you can explain what you want to achieve?)If you want to keep the list of hits returned by
findso you can do additional things afterfindfinishes, make it output the hits like in the last example, and store the output in a file or pipe it to another command like in the first example.