

Knowing the difference between these 2 lines of bash can save your day - mangeletti

Exhibit 1 (ok):<p><pre><code>    find . -name [pattern] -delete
</code></pre>
Exhibit 2 (bad):<p><pre><code>    find . - name [pattern] -delete
</code></pre>
It&#x27;s a good idea to take a quick second look at the command you&#x27;re about to run, to make sure there aren&#x27;t any typos. I learned this the hard way today.
======
leni536
I would advise to always run "find [...] -delete" commands without the -delete
option first. You can screw up a find command at multiple places.

~~~
partisan
This is similar to when you run a DELETE statement in SQL. Run it as a select
statement first to make sure you have the correct records.

~~~
trcollinson
If you absolutely have to run a sql command by hand, it is also a good idea to
wrap it in a transaction. Check the delete before committing the transaction,
or roll back.

~~~
davismwfl
Totally agree here. The only exception I have had a few times is when the
statement would destroy the transaction log and make the server unresponsive.
Working in SQL Server a few years back and having to run some very large
deletes instead of truncates (mostly because of a poor design and less than
ideal schemas), I found it was BAD to do this and so I had to change my ways.

Overall, I like to write SQL scripts that when they go to production are
always rerun safe and just overall safe, e.g. Create a transaction, Run
expected counts etc then Run the delete, do counts or other queries to insure
what happened was what I intended and then commit or rollback. This way my
scripts were basically safe in almost all circumstances. Until I hit the crazy
DB with huge tables and massively wide tables where my one transaction would
trash the transaction log and tempdb and cause SQL to go FU and stop. Ooops.
Back to simple select testing it was. Eventually we got the schema's mostly
fixed and got a DBA that fixed a lot of stupid on the setup, but still we
couldn't run transactions a lot of time because of stupid design choices made
way ahead of our involvement.

------
dllthomas
This is why we should have syntax highlighting in the shell...

------
informatimago
I would advise to always run find ... -print before find ... -delete.

~~~
SEJeff
With gnu find, -print is a default flag, so entirely redundant :)

As a sysadmin with 15ish years of experience, I'd also advise never blindly
running a destructive command such as the find -delete without at least first
seeing what it is doing.

