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:
- Linux finds
file2.log. - It asks:
< rm ... ./file2.log > ? - If you type
yand press Enter, the file is deleted. - If you type
nand 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