Don’t ask me how I learned this.
Don’t ask me how I learned this.
1. Start a transaction before even thinking of writing the delete/update/etc (BEGIN; ...)
2. Always write the WHERE query out first, THEN go back to the start of the line and fill out the DELETE/UPDATE/etc.
It worked well, and it's a habit I've since tried to keep on doing myself as well.
Now I have learnt to instinctively stop before doing anything destructive and double-check and double-check again! This also applies to SQL `DELETE` and `UPDATE`!
I know that `-r` was not neccessary but hey that was a biiiig mistake of mine!
find /backups/ -mtime '-30' -printf 'rm -f %p\n' > very_scary_deletes.sh
This gives you a static script with a bunch of rm's. You can read that, check it, give it to people to validate and when you eventually run it, it deletes exactly those files.Another way is sometimes: `echo *.txt~` and when you like the result, replace `echo` with `rm`.
One of my "oopsies" involved aggressive <up> and <enter> usage and a previous `rm -rf *` running in /home...
Though for me, I think the greater risk would be from not having a record of what I'd run.
rm ./~ is likely the easiest.
Another option, shell dependent, would be to turn off shell globbing.
The `GNU` version of `find` has a `-maxdepth` option so
find . -iname '~' -maxdepth 1 -exec rm {} \;
would work, but I don't like relying on `GNU` extensions.
Joke's on you, we all learned it this exact way.
thankfully my boss at the time was a amazing db admin and he helped me fixing my mistake.
Turns out when you start loading millions of rows of useless data into memory, the useful data has to get kicked out, and that makes query latency skyrocket.