1

I'm trying to execute a command repeatedly on every LOL file in a directory and have the output share the base name. My first thought is find . -type f -iname '*.lol' -exec command {} {}.out \: I know this will result in a lot of lol.out files, but I can rename those in a second step. The problem I'm having is that the command is failing on every file, although I can manually type it in successfully. I would like to debug my metacommand, but I don't know how to see the command that is actually being executed. Is there a way to get find to generate the list of commands it intends to execute?

  • 1
    you could maybe place an echo in the command handed off to -exec – Alexej Magura Jan 27 '17 at 17:18
  • That did it! Simple answers are always the best. – user212803 Jan 27 '17 at 17:20
  • Is this another meaning of LOL? – Philip Kirkbride Jan 27 '17 at 17:53
  • 1
    I assume it's just a typo but your -exec must end with a quoted semicolon ; not colon : – dave_thompson_085 Jan 27 '17 at 19:52
4

Use -ok in place of -exec. This displays the command that find is about to run and will ask for confirmation. The -ok flag is in every other way exactly equal to the -exec flag.

The command is not executed if anything other than y is given at the confirmation prompt.

  • I can see where that would be necessary for destructive commands. – user212803 Jan 27 '17 at 17:24
  • 1
    @user212803 ... or just any command that you need to get right. – Kusalananda Jan 27 '17 at 17:26

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.