1

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*}

1 Answer 1

2

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}"' {} \;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .