Help understanding `find` syntax on Solaris

Consider the adhering to documents:

$ find findtest                     
findtest
findtest/test1
findtest/test1/start.ksh
findtest/test2
findtest/test2/start.ksh
findtest/test3
findtest/test3/start.ksh
findtest/test4
findtest/test4/start.ksh

My inquiry has to do with making use of {} in the -exec call. It functions as I would certainly anticipate it when marking the outcome documents:

$ find findtest -name test[1-4] -exec ls -d {} \;           
findtest/test1
findtest/test2
findtest/test3
findtest/test4

However it does not appear to be increased when made use of in a course:

$ find findtest -name test[1-4] -exec md5sum {}/start.ksh \;     
md5sum: {}/start.ksh: No such file or directory
md5sum: {}/start.ksh: No such file or directory
md5sum: {}/start.ksh: No such file or directory
md5sum: {}/start.ksh: No such file or directory

How can I make use of find -type d -exec to accessibility lower power structure documents? I recognize I can make use of a for loop similar to this, yet I wonder to recognize if it can be carried out in one find call:

$ for f in $(find findtest -name test[1-4]); do md5sum "$f"/start.ksh; done
d41d8cd98f00b204e9800998ecf8427e  findtest/test1/start.ksh
d41d8cd98f00b204e9800998ecf8427e  findtest/test2/start.ksh
d41d8cd98f00b204e9800998ecf8427e  findtest/test3/start.ksh
d41d8cd98f00b204e9800998ecf8427e  findtest/test4/start.ksh
2
2022-06-07 14:40:17
Source Share
Answers: 2

The POSIX standard for the find command just mandates a separated to be changed by the filename, and also just the first one. Making use of {}/start.ksh bring about undefined actions.

An argument having just both personalities " " will be changed by the set of aggregated pathnames, with each pathname passed as a different argument to the invoked energy in the very same order that it was accumulated. The dimension of any kind of set of 2 or even more pathnames will be restricted such that implementation of the energy does not create the system is ARG_MAX restriction to be gone beyond. If greater than one argument having just both personalities " " exists, the actions is undefined.

If a utility_name or argument string has both personalities " ", yet not simply both personalities " ", it is execution - specified whether find changes those 2 personalities or makes use of the string without adjustment.

One means to do what you desire with Solaris find would certainly be that command:

find findtest -name "test[1-4]" -exec sh -c 'md5sum $1/start.ksh' foo {} \;

A faster means would certainly be:

find findtest -name "test[1-4]" -exec sh -c 'for i; do md5sum "$i/start.ksh"; done' foo {} + 
4
2022-06-07 15:08:34
Source
  1. Actually your covering is increasing test[1-4] prior to it conjures up find. You require to leave it with '…'
  2. {} obtains dealt with as pattern just when it is being a different token

-exec itself is generally costy and also advised to be made use of either with routing +, or stayed clear of for feeding xargs.

I recognize I can make use of a for loop similar to this, yet I wonder to recognize if it can be carried out in one find call:

find findtest -name 'test[1-4]' -print0 | xargs -0I{} -- md5sum '{}/start.ksh' bdsh runs md5sum successfully bdsh with all documents names offered simultaneously.

1
2022-06-07 15:08:03
Source