I was wondering if they was a way to prevent some commands from being executed in order to prevent from bad manipulation sometimes (for exemple you execute "rm *.py" when you wanted to execute "rm *.pyc" or something like that).
People will say that it's the user's responsability to check his inputs and it's right but I would like to know anyway if there's a way.
For "basic" things, we can use aliases in our bashrc like :
alias apt-get="echo 'We use aptitude here !'"
alias sl="echo 'Did you mean ls ?'"
But for something with arguments like "rm -f *.py" (or "rm -Rf /"), this simple trick don't work. Of course, I just want a basic method that prevent the exact command to be executed (same spaces and same arguments ordering would be a good start).
Thank you very much for your answers.
Correction to my ls function example:
Then:
Well, you can use the time-honoured approach of putting one of your own path components in front of all the others:
and then, in
~/safebin
, you put scripts that are "safer" likerm
:That script outputs for
rm *
:Now obviously the
"${fspec: -3}" = ".py"
is a simplistic one and a black list. I'd probably prefer to have a white list of things I was allowed to delete and deny everything else.And here's a white list version based on regular expressions:
which outputs:
You may also use the lesser-known command "command" (which is similar to the "builtin" command) to create a restrictive rm wrapper:
ThR37 says:
Here's a short python script based on the idea of simply wrapping command like "rm". Bash wrapper are maybe a better idea but I like python :) :
You might want to take a look at this http://code.google.com/p/safe-rm/