Using the Linux find command with caution

By Sandra Henry-Stocker

A friend just recently reminded me of a useful option that can add a little caution to the commands that I run with the Linux find command. It’s called -ok and it works like the -exec option except for one important difference – it makes the find command ask for permission before taking the specified action.

Here’s an example. If you were looking for files that you intended to remove from the system using find, you might run a command like this:

$ find . -name runme -exec rm {} ;

Anywhere within the current directory and its subdirectories, any files named “runme” would be summarily removed – provided, of course, that you have permission to remove them. Use the -ok command instead, and you’ll see something like this. The find command will ask for approval before removing the files. Answering y for “yes” would allow the find command to go ahead and remove the files one by one.

To read this article in full or to leave a comment, please click here

From: Network World

Share