1

Can someone show me how to replace -exec with -ok in the command below?

find -name "*.swp" -exec rm {} "\;"

I'm told, and it says it on the "man page", that you can use -ok to "confirm".

I replaced -exec with -ok but I got an error:

find: missing argument to 'ok'

This is on ParrotOS.

3
  • 2
    Which platform is this on? The command find -name "*.swp" -ok rm {} ";" ran without errors for me on Manjaro Commented Sep 12, 2021 at 17:38
  • Thanks - I'm using parrot os
    – Bebe1980
    Commented Sep 12, 2021 at 17:43
  • @GraceThompson the OP was using "\;" but the site ate the \ since it wasn't in a code block.
    – terdon
    Commented Sep 12, 2021 at 18:11

1 Answer 1

5

The command you show would give the exact same error. You need to end an -exec or -ok with a ;. The ; has a special meaning in the shell (e.g. bash) which is why this needs to be escaped, either as ";" or as \;, but not both ("\;"), as you had in your question.

So try this:

find -name "*.swp" -ok rm {} \;

This will ask for confirmation before deleting each file. You can also get the same behavior, since you're on Linux, with rm -i:

find -name "*.swp" -exec rm -i {} \;
1
  • Thanks, yes it works with just \; - Unfortunately in my LFS101x Introduction to Linux course - they appear to have got it wrong by telling me I can use either ';' or "\;"!
    – Bebe1980
    Commented Sep 13, 2021 at 0:32

You must log in to answer this question.

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