Recursively *.ext files using find

HI,

Getting the syntax error " find: missing conjunction" for the below code

D1_DIR=/x/y/z
D1_NAME=file_name
FILE_DIR=pset
for file in `find ${D1_DIR}/${D1_NAME} -name "*\.${FILE_DIR}" /dev/null {} \;`
do
                echo $file
done

#Trying to find all the files with *.pset extension in the folder ${D1_DIR}/${D1_NAME} recursively and trying to loop through each file.

please let me know the fix for the error.

thanks

Remove the below part from find command and run

 /dev/null {} \;
1 Like

The error is coming from the superflous /dev/null and the extra punctuation.

The loop would be much more robust with while instead of for :

find "${D1_DIR}/${D1_NAME}" -name "*\.${FILE_DIR}" -print | while read file
do
                echo "${file}"
done
1 Like

I have the list of files to be processed in another input file. Now with in the for/while loop i need to restrict my processing only for the files present in input file.

let me know how to achieve the same. thanks.

---------- Post updated at 05:54 AM ---------- Previous update was at 05:53 AM ----------

thanks a lot for your reply

Please post a couple of example lines from "input file" making it clear whether the file contains full paths.

I think the

/dev/null

is not superflous; it is just used wrongly. It might be necessary when any of the sub-directories in the search path do not have execute permissions. In such a case, it's better to redirect standard error to

/dev/null

.