With this line of code I generate an output of every result.

exec("find ics/ -mmin +3 -type f -name '*.pdx' -exec basename {} ';' > ./tmp/filename") 

How can I generate a file with dynamic file name everytime? Like this:

./tmp/filename_{*Here should be the dynamic name*}

You can start a new shell and provide the file as an argument. Then use POSIX parameter expansion to get rid of the path and —if desired— the extension:

find . -type f -name "*.pdx" \
  -exec sh -c \
    'base="${0##*/}"; printf "%s\n" "$base" > ./tmp/filename_"${base%.pdx}"' {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.