Disallow `rm` to remove `*`Trash Filing SystemFile handling scriptBash script to remove unwanted git...

Is the differential, dp, exact or not?

Is there a logarithm base for which the logarithm becomes an identity function?

Can I challenge the interviewer to give me a proper technical feedback?

Is it appropriate to ask a former professor to order a library book for me through ILL?

Can multiple states demand income tax from an LLC?

Was this cameo in Captain Marvel computer generated?

How do you make a gun that shoots melee weapons and/or swords?

Should we avoid writing fiction about historical events without extensive research?

An Undercover Army

Will the concrete slab in a partially heated shed conduct a lot of heat to the unconditioned area?

A running toilet that stops itself

What would be the most expensive material to an intergalactic society?

What the error in writing this equation by latex?

Draw this image in the TIKZ package

What is Tony Stark injecting into himself in Iron Man 3?

Who has more? Ireland or Iceland?

Can Witch Sight see through Mirror Image?

What is the oldest European royal house?

Create chunks from an array

Boss Telling direct supervisor I snitched

How does a sound wave propagate?

Where is the License file location for Identity Server in Sitecore 9.1?

What is the best index strategy or query SELECT when performing a search/lookup BETWEEN IP address (IPv4 and IPv6) ranges?

Is this Paypal Github SDK reference really a dangerous site?



Disallow `rm` to remove `*`


Trash Filing SystemFile handling scriptBash script to remove unwanted git objectsMaking time lapse screenshots using BashBash Script - batch rename files in current directory with previewBash script for referencing git status output filesRemove every line that include and follows the second occurrence of a given patternRemoving commented dead code without removing the legitimate comments













0












$begingroup$


This is a script in bash 4.4 that I have used for long for preventing rm * and rm -rf * from accidentally invoked and removing important files by mistake. I put it in my ~/.bash_aliases.



alias rm='set -f;rm'
rm(){
if [[ "$-" == *i* ]]
then
if [ "$1" = "*" ] || [ "$2" = "*" ] || [ "$1" = "./*" ] || [ "$2" = "./*" ]
then
echo "Abort: refusing to remove *, please go to the parent folder and do rm <folder_name>/*" 1>&2
set +f
return 1
fi
fi
set +f
/bin/rm -i $@
}

set +f


I would like to know whether there are any vulnerabilities and whether it can be improved.










share|improve this question









$endgroup$

















    0












    $begingroup$


    This is a script in bash 4.4 that I have used for long for preventing rm * and rm -rf * from accidentally invoked and removing important files by mistake. I put it in my ~/.bash_aliases.



    alias rm='set -f;rm'
    rm(){
    if [[ "$-" == *i* ]]
    then
    if [ "$1" = "*" ] || [ "$2" = "*" ] || [ "$1" = "./*" ] || [ "$2" = "./*" ]
    then
    echo "Abort: refusing to remove *, please go to the parent folder and do rm <folder_name>/*" 1>&2
    set +f
    return 1
    fi
    fi
    set +f
    /bin/rm -i $@
    }

    set +f


    I would like to know whether there are any vulnerabilities and whether it can be improved.










    share|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      This is a script in bash 4.4 that I have used for long for preventing rm * and rm -rf * from accidentally invoked and removing important files by mistake. I put it in my ~/.bash_aliases.



      alias rm='set -f;rm'
      rm(){
      if [[ "$-" == *i* ]]
      then
      if [ "$1" = "*" ] || [ "$2" = "*" ] || [ "$1" = "./*" ] || [ "$2" = "./*" ]
      then
      echo "Abort: refusing to remove *, please go to the parent folder and do rm <folder_name>/*" 1>&2
      set +f
      return 1
      fi
      fi
      set +f
      /bin/rm -i $@
      }

      set +f


      I would like to know whether there are any vulnerabilities and whether it can be improved.










      share|improve this question









      $endgroup$




      This is a script in bash 4.4 that I have used for long for preventing rm * and rm -rf * from accidentally invoked and removing important files by mistake. I put it in my ~/.bash_aliases.



      alias rm='set -f;rm'
      rm(){
      if [[ "$-" == *i* ]]
      then
      if [ "$1" = "*" ] || [ "$2" = "*" ] || [ "$1" = "./*" ] || [ "$2" = "./*" ]
      then
      echo "Abort: refusing to remove *, please go to the parent folder and do rm <folder_name>/*" 1>&2
      set +f
      return 1
      fi
      fi
      set +f
      /bin/rm -i $@
      }

      set +f


      I would like to know whether there are any vulnerabilities and whether it can be improved.







      bash






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 12 mins ago









      Weijun ZhouWeijun Zhou

      1285




      1285






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215069%2fdisallow-rm-to-remove%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215069%2fdisallow-rm-to-remove%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...