GNU bug report logs -
#37686
Feature request: flag to not remove any files if any argument doesn't exist or is a directory
Previous Next
Full log
View this message in rfc822 format
On 2019/10/09 14:01, Mark Friedenbach wrote:
> I have a persistent problem that has caused me serious trouble in the
> past: I mixup 'rm' and 'mv'. I suspect this is because on my keyboard
> they are typed with the same fingers and muscle memory kicks in,
> especially if I just typed the other command recently.
>
rm () {
if [[ -t 0 ]]; then echo >&2 Disallowed;return 1; fi
command "$FUNCNAME" "$@"
}
mv () {
if [[ -t 0 ]]; then echo >&2 Disallowed;return 1; fi
command "$FUNCNAME" "$@"
}
alias move='</dev/null mv'
alias remove='</dev/null rm'
How about something _like_ the above (spur of the moment idea,
written in 'bash'...
Interactively, you type 'move' or 'remove'
(or whatever you want to name them). But scripts you run
won't be affected.
Might have to adjust for your use case, but might protect against
most cases.
Nightly backups also help prevent catastrophic problems.
At the same time, with functions or aliases, you could test for
the existence of the arguments before actually executing them.
This bug report was last modified 5 years and 311 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.