What does the `-ok` option do?

QuestionsQuestions8 SkillsProDec, 19 2025
0105

The -ok option is the safe version of the -exec option.

While -exec runs a command immediately on every file found, -ok asks for your permission before running the command on each individual file.

How it works:

When you use -ok, Linux will display the command it wants to run and wait for you to type y (for yes) or n (for no).

Example:

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

What happens on your screen:

  1. Linux finds file2.log.
  2. It asks: < rm ... ./file2.log > ?
  3. If you type y and press Enter, the file is deleted.
  4. If you type n and press Enter, it skips that file and moves to the next one.

Why use it?

It is highly recommended for destructive operations like rm (remove) or mv (move). It prevents accidental bulk deletions if your search pattern (like *) matches more files than you originally intended.

Think of it as a "confirm before action" safety switch

0 Comments

no data
Be the first to share your comment!