Bash command to delete a certain file in * folders












4














I have a .desktop file that execs with bash -c to set an environment variable then load the program. Now I need to add another command before it goes to loading the program.



Sometimes the program creates file called SOFT_REPAIR in ~/path to/*/, and I need to delete it before running the program. * represents whatever version the program maybe, and as /path to/ implies, there's spaces in the folder names within which the SOFT_REPAIR resides.



So here's the thing:




  • Do I need to do /path to/?

  • Will rm 'path to/*/SOFT_REPAIR/' work?

  • Can I just use the rm command whether SOFT_REPAIR exists or not, or do I need to use the if statement?










share|improve this question





























    4














    I have a .desktop file that execs with bash -c to set an environment variable then load the program. Now I need to add another command before it goes to loading the program.



    Sometimes the program creates file called SOFT_REPAIR in ~/path to/*/, and I need to delete it before running the program. * represents whatever version the program maybe, and as /path to/ implies, there's spaces in the folder names within which the SOFT_REPAIR resides.



    So here's the thing:




    • Do I need to do /path to/?

    • Will rm 'path to/*/SOFT_REPAIR/' work?

    • Can I just use the rm command whether SOFT_REPAIR exists or not, or do I need to use the if statement?










    share|improve this question



























      4












      4








      4







      I have a .desktop file that execs with bash -c to set an environment variable then load the program. Now I need to add another command before it goes to loading the program.



      Sometimes the program creates file called SOFT_REPAIR in ~/path to/*/, and I need to delete it before running the program. * represents whatever version the program maybe, and as /path to/ implies, there's spaces in the folder names within which the SOFT_REPAIR resides.



      So here's the thing:




      • Do I need to do /path to/?

      • Will rm 'path to/*/SOFT_REPAIR/' work?

      • Can I just use the rm command whether SOFT_REPAIR exists or not, or do I need to use the if statement?










      share|improve this question















      I have a .desktop file that execs with bash -c to set an environment variable then load the program. Now I need to add another command before it goes to loading the program.



      Sometimes the program creates file called SOFT_REPAIR in ~/path to/*/, and I need to delete it before running the program. * represents whatever version the program maybe, and as /path to/ implies, there's spaces in the folder names within which the SOFT_REPAIR resides.



      So here's the thing:




      • Do I need to do /path to/?

      • Will rm 'path to/*/SOFT_REPAIR/' work?

      • Can I just use the rm command whether SOFT_REPAIR exists or not, or do I need to use the if statement?







      bash .desktop






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 20 '18 at 0:17









      Rui F Ribeiro

      39k1479130




      39k1479130










      asked Feb 16 '14 at 9:42









      Oxwivi

      67821123




      67821123






















          2 Answers
          2






          active

          oldest

          votes


















          3














          To solve your original problem:



          find ~/'path to'/ -name SOFT_REPAIR -exec rm -f "{}" ;


          or, if you have GNU find:



          find ~/'path to'/ -name SOFT_REPAIR -delete


          To answer your questions:




          • You need to backslash-escape the spaces in the file names if you don't wrap them in quotes.


          • No, because the quotes prevent shell glob expansion. This should work, though:



            rm 'path to'/*/SOFT_REPAIR/


            assuming that SOFT_REPAIR resides only two levels below path to/



          • rm on a non-existent file will throw an error. rm -f will fail silently (at least in the GNU implementation of rm).







          share|improve this answer























          • Deleting with the find command won't throw a tantrum if SOFT_REPAIR is non-existent, right?
            – Oxwivi
            Feb 16 '14 at 13:07












          • Also, will find recursively look into the subdirectories or do I need to specify exactly where the file is? If that is so, it defeats the purpose, because neither I nor the .desktop file will know the latest version of the program and subsequently the name of the folder with SOFT_REPAIR in it.
            – Oxwivi
            Feb 16 '14 at 13:15










          • @Oxwivi find will not complain. It just applies the actions to any files it finds. Also, it operates recursively.
            – Joseph R.
            Feb 16 '14 at 13:17










          • Trying it out answered my question. Many thanks!
            – Oxwivi
            Feb 16 '14 at 13:23



















          2














          Yes, this works. Simply use rm -f path to/*/SOFT_REPAIR.



          But why don't you simply try yourself?



          michas@lenny:~/t$ mkdir -p path to/{foo,bar}
          michas@lenny:~/t$ touch path to/{foo,bar}/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          | `-- SOFT_REPAIR
          `-- foo
          `-- SOFT_REPAIR

          3 directories, 2 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          rm: cannot remove 'path to/*/SOFT_REPAIR': No such file or directory
          michas@lenny:~/t$ rm -f path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files





          share|improve this answer























          • Nicely summarized, thank you very much!
            – Oxwivi
            Feb 16 '14 at 13:10










          • Unfortunately the alternative solution suggested by @Joseph suits the situation I described better. Sorry!
            – Oxwivi
            Feb 17 '14 at 15:39











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          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%2funix.stackexchange.com%2fquestions%2f115391%2fbash-command-to-delete-a-certain-file-in-folders%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          To solve your original problem:



          find ~/'path to'/ -name SOFT_REPAIR -exec rm -f "{}" ;


          or, if you have GNU find:



          find ~/'path to'/ -name SOFT_REPAIR -delete


          To answer your questions:




          • You need to backslash-escape the spaces in the file names if you don't wrap them in quotes.


          • No, because the quotes prevent shell glob expansion. This should work, though:



            rm 'path to'/*/SOFT_REPAIR/


            assuming that SOFT_REPAIR resides only two levels below path to/



          • rm on a non-existent file will throw an error. rm -f will fail silently (at least in the GNU implementation of rm).







          share|improve this answer























          • Deleting with the find command won't throw a tantrum if SOFT_REPAIR is non-existent, right?
            – Oxwivi
            Feb 16 '14 at 13:07












          • Also, will find recursively look into the subdirectories or do I need to specify exactly where the file is? If that is so, it defeats the purpose, because neither I nor the .desktop file will know the latest version of the program and subsequently the name of the folder with SOFT_REPAIR in it.
            – Oxwivi
            Feb 16 '14 at 13:15










          • @Oxwivi find will not complain. It just applies the actions to any files it finds. Also, it operates recursively.
            – Joseph R.
            Feb 16 '14 at 13:17










          • Trying it out answered my question. Many thanks!
            – Oxwivi
            Feb 16 '14 at 13:23
















          3














          To solve your original problem:



          find ~/'path to'/ -name SOFT_REPAIR -exec rm -f "{}" ;


          or, if you have GNU find:



          find ~/'path to'/ -name SOFT_REPAIR -delete


          To answer your questions:




          • You need to backslash-escape the spaces in the file names if you don't wrap them in quotes.


          • No, because the quotes prevent shell glob expansion. This should work, though:



            rm 'path to'/*/SOFT_REPAIR/


            assuming that SOFT_REPAIR resides only two levels below path to/



          • rm on a non-existent file will throw an error. rm -f will fail silently (at least in the GNU implementation of rm).







          share|improve this answer























          • Deleting with the find command won't throw a tantrum if SOFT_REPAIR is non-existent, right?
            – Oxwivi
            Feb 16 '14 at 13:07












          • Also, will find recursively look into the subdirectories or do I need to specify exactly where the file is? If that is so, it defeats the purpose, because neither I nor the .desktop file will know the latest version of the program and subsequently the name of the folder with SOFT_REPAIR in it.
            – Oxwivi
            Feb 16 '14 at 13:15










          • @Oxwivi find will not complain. It just applies the actions to any files it finds. Also, it operates recursively.
            – Joseph R.
            Feb 16 '14 at 13:17










          • Trying it out answered my question. Many thanks!
            – Oxwivi
            Feb 16 '14 at 13:23














          3












          3








          3






          To solve your original problem:



          find ~/'path to'/ -name SOFT_REPAIR -exec rm -f "{}" ;


          or, if you have GNU find:



          find ~/'path to'/ -name SOFT_REPAIR -delete


          To answer your questions:




          • You need to backslash-escape the spaces in the file names if you don't wrap them in quotes.


          • No, because the quotes prevent shell glob expansion. This should work, though:



            rm 'path to'/*/SOFT_REPAIR/


            assuming that SOFT_REPAIR resides only two levels below path to/



          • rm on a non-existent file will throw an error. rm -f will fail silently (at least in the GNU implementation of rm).







          share|improve this answer














          To solve your original problem:



          find ~/'path to'/ -name SOFT_REPAIR -exec rm -f "{}" ;


          or, if you have GNU find:



          find ~/'path to'/ -name SOFT_REPAIR -delete


          To answer your questions:




          • You need to backslash-escape the spaces in the file names if you don't wrap them in quotes.


          • No, because the quotes prevent shell glob expansion. This should work, though:



            rm 'path to'/*/SOFT_REPAIR/


            assuming that SOFT_REPAIR resides only two levels below path to/



          • rm on a non-existent file will throw an error. rm -f will fail silently (at least in the GNU implementation of rm).








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 23 '17 at 12:40









          Community

          1




          1










          answered Feb 16 '14 at 10:15









          Joseph R.

          28k373114




          28k373114












          • Deleting with the find command won't throw a tantrum if SOFT_REPAIR is non-existent, right?
            – Oxwivi
            Feb 16 '14 at 13:07












          • Also, will find recursively look into the subdirectories or do I need to specify exactly where the file is? If that is so, it defeats the purpose, because neither I nor the .desktop file will know the latest version of the program and subsequently the name of the folder with SOFT_REPAIR in it.
            – Oxwivi
            Feb 16 '14 at 13:15










          • @Oxwivi find will not complain. It just applies the actions to any files it finds. Also, it operates recursively.
            – Joseph R.
            Feb 16 '14 at 13:17










          • Trying it out answered my question. Many thanks!
            – Oxwivi
            Feb 16 '14 at 13:23


















          • Deleting with the find command won't throw a tantrum if SOFT_REPAIR is non-existent, right?
            – Oxwivi
            Feb 16 '14 at 13:07












          • Also, will find recursively look into the subdirectories or do I need to specify exactly where the file is? If that is so, it defeats the purpose, because neither I nor the .desktop file will know the latest version of the program and subsequently the name of the folder with SOFT_REPAIR in it.
            – Oxwivi
            Feb 16 '14 at 13:15










          • @Oxwivi find will not complain. It just applies the actions to any files it finds. Also, it operates recursively.
            – Joseph R.
            Feb 16 '14 at 13:17










          • Trying it out answered my question. Many thanks!
            – Oxwivi
            Feb 16 '14 at 13:23
















          Deleting with the find command won't throw a tantrum if SOFT_REPAIR is non-existent, right?
          – Oxwivi
          Feb 16 '14 at 13:07






          Deleting with the find command won't throw a tantrum if SOFT_REPAIR is non-existent, right?
          – Oxwivi
          Feb 16 '14 at 13:07














          Also, will find recursively look into the subdirectories or do I need to specify exactly where the file is? If that is so, it defeats the purpose, because neither I nor the .desktop file will know the latest version of the program and subsequently the name of the folder with SOFT_REPAIR in it.
          – Oxwivi
          Feb 16 '14 at 13:15




          Also, will find recursively look into the subdirectories or do I need to specify exactly where the file is? If that is so, it defeats the purpose, because neither I nor the .desktop file will know the latest version of the program and subsequently the name of the folder with SOFT_REPAIR in it.
          – Oxwivi
          Feb 16 '14 at 13:15












          @Oxwivi find will not complain. It just applies the actions to any files it finds. Also, it operates recursively.
          – Joseph R.
          Feb 16 '14 at 13:17




          @Oxwivi find will not complain. It just applies the actions to any files it finds. Also, it operates recursively.
          – Joseph R.
          Feb 16 '14 at 13:17












          Trying it out answered my question. Many thanks!
          – Oxwivi
          Feb 16 '14 at 13:23




          Trying it out answered my question. Many thanks!
          – Oxwivi
          Feb 16 '14 at 13:23













          2














          Yes, this works. Simply use rm -f path to/*/SOFT_REPAIR.



          But why don't you simply try yourself?



          michas@lenny:~/t$ mkdir -p path to/{foo,bar}
          michas@lenny:~/t$ touch path to/{foo,bar}/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          | `-- SOFT_REPAIR
          `-- foo
          `-- SOFT_REPAIR

          3 directories, 2 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          rm: cannot remove 'path to/*/SOFT_REPAIR': No such file or directory
          michas@lenny:~/t$ rm -f path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files





          share|improve this answer























          • Nicely summarized, thank you very much!
            – Oxwivi
            Feb 16 '14 at 13:10










          • Unfortunately the alternative solution suggested by @Joseph suits the situation I described better. Sorry!
            – Oxwivi
            Feb 17 '14 at 15:39
















          2














          Yes, this works. Simply use rm -f path to/*/SOFT_REPAIR.



          But why don't you simply try yourself?



          michas@lenny:~/t$ mkdir -p path to/{foo,bar}
          michas@lenny:~/t$ touch path to/{foo,bar}/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          | `-- SOFT_REPAIR
          `-- foo
          `-- SOFT_REPAIR

          3 directories, 2 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          rm: cannot remove 'path to/*/SOFT_REPAIR': No such file or directory
          michas@lenny:~/t$ rm -f path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files





          share|improve this answer























          • Nicely summarized, thank you very much!
            – Oxwivi
            Feb 16 '14 at 13:10










          • Unfortunately the alternative solution suggested by @Joseph suits the situation I described better. Sorry!
            – Oxwivi
            Feb 17 '14 at 15:39














          2












          2








          2






          Yes, this works. Simply use rm -f path to/*/SOFT_REPAIR.



          But why don't you simply try yourself?



          michas@lenny:~/t$ mkdir -p path to/{foo,bar}
          michas@lenny:~/t$ touch path to/{foo,bar}/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          | `-- SOFT_REPAIR
          `-- foo
          `-- SOFT_REPAIR

          3 directories, 2 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          rm: cannot remove 'path to/*/SOFT_REPAIR': No such file or directory
          michas@lenny:~/t$ rm -f path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files





          share|improve this answer














          Yes, this works. Simply use rm -f path to/*/SOFT_REPAIR.



          But why don't you simply try yourself?



          michas@lenny:~/t$ mkdir -p path to/{foo,bar}
          michas@lenny:~/t$ touch path to/{foo,bar}/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          | `-- SOFT_REPAIR
          `-- foo
          `-- SOFT_REPAIR

          3 directories, 2 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files
          michas@lenny:~/t$ rm path to/*/SOFT_REPAIR
          rm: cannot remove 'path to/*/SOFT_REPAIR': No such file or directory
          michas@lenny:~/t$ rm -f path to/*/SOFT_REPAIR
          michas@lenny:~/t$ tree
          .
          `-- path to
          |-- bar
          `-- foo

          3 directories, 0 files






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 16 '14 at 10:27

























          answered Feb 16 '14 at 10:15









          michas

          15.1k33771




          15.1k33771












          • Nicely summarized, thank you very much!
            – Oxwivi
            Feb 16 '14 at 13:10










          • Unfortunately the alternative solution suggested by @Joseph suits the situation I described better. Sorry!
            – Oxwivi
            Feb 17 '14 at 15:39


















          • Nicely summarized, thank you very much!
            – Oxwivi
            Feb 16 '14 at 13:10










          • Unfortunately the alternative solution suggested by @Joseph suits the situation I described better. Sorry!
            – Oxwivi
            Feb 17 '14 at 15:39
















          Nicely summarized, thank you very much!
          – Oxwivi
          Feb 16 '14 at 13:10




          Nicely summarized, thank you very much!
          – Oxwivi
          Feb 16 '14 at 13:10












          Unfortunately the alternative solution suggested by @Joseph suits the situation I described better. Sorry!
          – Oxwivi
          Feb 17 '14 at 15:39




          Unfortunately the alternative solution suggested by @Joseph suits the situation I described better. Sorry!
          – Oxwivi
          Feb 17 '14 at 15:39


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux 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.


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





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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.


          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%2funix.stackexchange.com%2fquestions%2f115391%2fbash-command-to-delete-a-certain-file-in-folders%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

          Morgemoulin

          Scott Moir

          Souastre