The Danger of Automation
In Ubuntu Linux, the find command allows you to locate files and automatically run a secondary command on them using the -exec flag. While incredibly powerful, this is also highly dangerous. If you write a command to find and automatically delete (rm) all files older than 365 days, a single typo could result in the silent, instant destruction of critical system data before you even realize your mistake. If you are executing destructive commands, you must instruct the search engine to pause and ask for your explicit permission before executing the action on each individual file.
Using the find Command with -ok
The Linux find command utilizes the -ok flag as a safe, interactive alternative to -exec.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To search the
/tmp/directory for text files and delete them, but with a manual safety confirmation required for every single file, type the following command exactly: sudo find /tmp/ -name "*.txt" -ok rm {} \;- Press Enter and provide your administrator password.
The Interactive Prompt
The syntax for -ok is identical to -exec (requiring the {} placeholders and the \; terminator). However, the execution behavior is fundamentally different. When the search engine finds a matching text file, it will completely halt the script and display a prompt in the terminal, such as < rm ... /tmp/example.txt > ?. You must type y (yes) and press Enter to execute the deletion, or type n (no) to skip the file and move to the next one, guaranteeing you never delete a file by accident.