Pipe results of locate into rm












10















I tried running



locate *.orig | xargs rm


but it said No such file or directory



I've seen ways to do it with find but locate returns the full path to the object so it should be possible










share|improve this question





























    10















    I tried running



    locate *.orig | xargs rm


    but it said No such file or directory



    I've seen ways to do it with find but locate returns the full path to the object so it should be possible










    share|improve this question



























      10












      10








      10


      4






      I tried running



      locate *.orig | xargs rm


      but it said No such file or directory



      I've seen ways to do it with find but locate returns the full path to the object so it should be possible










      share|improve this question
















      I tried running



      locate *.orig | xargs rm


      but it said No such file or directory



      I've seen ways to do it with find but locate returns the full path to the object so it should be possible







      bash gnome-terminal rm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 22 '10 at 19:35







      soldier.moth

















      asked Oct 22 '10 at 19:24









      soldier.mothsoldier.moth

      132111




      132111






















          5 Answers
          5






          active

          oldest

          votes


















          19














          If filenames contain spaces you should use



          locate -0 $something | xargs -0 rm


          From locate man page:




          -0, --null Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).




          or



          locate $something | while read f; do rm "$f"; done


          Also, you should protect *.orig with quotes, to avoid the shell expansion, and pass it to locate untouched.






          share|improve this answer


























          • What do you mean by "shell expansion"?

            – soldier.moth
            Oct 22 '10 at 20:58













          • +1 for your second example. I always use | while read since my home directory is full of files with spaces.

            – matpie
            Oct 22 '10 at 21:35











          • @Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should.

            – enzotib
            Oct 23 '10 at 5:39











          • Also to grep locate output you can then tr 'n' ''.

            – Pablo Bianchi
            Jan 2 at 19:13



















          2














          It's xargs not xarg






          share|improve this answer
























          • That's what I meant was typing question from memory thank you though.

            – soldier.moth
            Oct 22 '10 at 19:35











          • Oh, ok. It looked like the error you'd get putting an incorrect command after |

            – maco
            Oct 22 '10 at 19:45



















          0














          The command locate *.orig | xargs rm does work actually but what was happening was that locate was finding *.orig files in the trash can and rm spits out the error No such file or directory when trying to delete files in the trash can.






          share|improve this answer
























          • You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.

            – enzotib
            Oct 23 '10 at 5:57











          • It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.

            – soldier.moth
            Oct 23 '10 at 6:25



















          0














          locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.



          Just use



          locate .orig


          and if that gets you what you need



          locate .orig | xargs rm


          or, as enzotib mentioned



          locate -0 .orig | xargs -0 rm


          if you have Whitespace in the filenames.






          share|improve this answer































            0














            A trick : Save all paths in tmp file . then , Loop on it:



            #!/bin/bash
            locate .orig /tmp/tmp.txt
            while read line
            do
            pth=$line
            rm "$pth"
            done < /tmp/tmp.txt

            rm -rf /tmp/tmp.txt





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              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: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2faskubuntu.com%2fquestions%2f8933%2fpipe-results-of-locate-into-rm%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              19














              If filenames contain spaces you should use



              locate -0 $something | xargs -0 rm


              From locate man page:




              -0, --null Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).




              or



              locate $something | while read f; do rm "$f"; done


              Also, you should protect *.orig with quotes, to avoid the shell expansion, and pass it to locate untouched.






              share|improve this answer


























              • What do you mean by "shell expansion"?

                – soldier.moth
                Oct 22 '10 at 20:58













              • +1 for your second example. I always use | while read since my home directory is full of files with spaces.

                – matpie
                Oct 22 '10 at 21:35











              • @Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should.

                – enzotib
                Oct 23 '10 at 5:39











              • Also to grep locate output you can then tr 'n' ''.

                – Pablo Bianchi
                Jan 2 at 19:13
















              19














              If filenames contain spaces you should use



              locate -0 $something | xargs -0 rm


              From locate man page:




              -0, --null Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).




              or



              locate $something | while read f; do rm "$f"; done


              Also, you should protect *.orig with quotes, to avoid the shell expansion, and pass it to locate untouched.






              share|improve this answer


























              • What do you mean by "shell expansion"?

                – soldier.moth
                Oct 22 '10 at 20:58













              • +1 for your second example. I always use | while read since my home directory is full of files with spaces.

                – matpie
                Oct 22 '10 at 21:35











              • @Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should.

                – enzotib
                Oct 23 '10 at 5:39











              • Also to grep locate output you can then tr 'n' ''.

                – Pablo Bianchi
                Jan 2 at 19:13














              19












              19








              19







              If filenames contain spaces you should use



              locate -0 $something | xargs -0 rm


              From locate man page:




              -0, --null Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).




              or



              locate $something | while read f; do rm "$f"; done


              Also, you should protect *.orig with quotes, to avoid the shell expansion, and pass it to locate untouched.






              share|improve this answer















              If filenames contain spaces you should use



              locate -0 $something | xargs -0 rm


              From locate man page:




              -0, --null Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).




              or



              locate $something | while read f; do rm "$f"; done


              Also, you should protect *.orig with quotes, to avoid the shell expansion, and pass it to locate untouched.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 2 at 18:28









              Pablo Bianchi

              2,4451530




              2,4451530










              answered Oct 22 '10 at 19:39









              enzotibenzotib

              63k6132154




              63k6132154













              • What do you mean by "shell expansion"?

                – soldier.moth
                Oct 22 '10 at 20:58













              • +1 for your second example. I always use | while read since my home directory is full of files with spaces.

                – matpie
                Oct 22 '10 at 21:35











              • @Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should.

                – enzotib
                Oct 23 '10 at 5:39











              • Also to grep locate output you can then tr 'n' ''.

                – Pablo Bianchi
                Jan 2 at 19:13



















              • What do you mean by "shell expansion"?

                – soldier.moth
                Oct 22 '10 at 20:58













              • +1 for your second example. I always use | while read since my home directory is full of files with spaces.

                – matpie
                Oct 22 '10 at 21:35











              • @Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should.

                – enzotib
                Oct 23 '10 at 5:39











              • Also to grep locate output you can then tr 'n' ''.

                – Pablo Bianchi
                Jan 2 at 19:13

















              What do you mean by "shell expansion"?

              – soldier.moth
              Oct 22 '10 at 20:58







              What do you mean by "shell expansion"?

              – soldier.moth
              Oct 22 '10 at 20:58















              +1 for your second example. I always use | while read since my home directory is full of files with spaces.

              – matpie
              Oct 22 '10 at 21:35





              +1 for your second example. I always use | while read since my home directory is full of files with spaces.

              – matpie
              Oct 22 '10 at 21:35













              @Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should.

              – enzotib
              Oct 23 '10 at 5:39





              @Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should.

              – enzotib
              Oct 23 '10 at 5:39













              Also to grep locate output you can then tr 'n' ''.

              – Pablo Bianchi
              Jan 2 at 19:13





              Also to grep locate output you can then tr 'n' ''.

              – Pablo Bianchi
              Jan 2 at 19:13













              2














              It's xargs not xarg






              share|improve this answer
























              • That's what I meant was typing question from memory thank you though.

                – soldier.moth
                Oct 22 '10 at 19:35











              • Oh, ok. It looked like the error you'd get putting an incorrect command after |

                – maco
                Oct 22 '10 at 19:45
















              2














              It's xargs not xarg






              share|improve this answer
























              • That's what I meant was typing question from memory thank you though.

                – soldier.moth
                Oct 22 '10 at 19:35











              • Oh, ok. It looked like the error you'd get putting an incorrect command after |

                – maco
                Oct 22 '10 at 19:45














              2












              2








              2







              It's xargs not xarg






              share|improve this answer













              It's xargs not xarg







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 22 '10 at 19:30









              macomaco

              12.5k32334




              12.5k32334













              • That's what I meant was typing question from memory thank you though.

                – soldier.moth
                Oct 22 '10 at 19:35











              • Oh, ok. It looked like the error you'd get putting an incorrect command after |

                – maco
                Oct 22 '10 at 19:45



















              • That's what I meant was typing question from memory thank you though.

                – soldier.moth
                Oct 22 '10 at 19:35











              • Oh, ok. It looked like the error you'd get putting an incorrect command after |

                – maco
                Oct 22 '10 at 19:45

















              That's what I meant was typing question from memory thank you though.

              – soldier.moth
              Oct 22 '10 at 19:35





              That's what I meant was typing question from memory thank you though.

              – soldier.moth
              Oct 22 '10 at 19:35













              Oh, ok. It looked like the error you'd get putting an incorrect command after |

              – maco
              Oct 22 '10 at 19:45





              Oh, ok. It looked like the error you'd get putting an incorrect command after |

              – maco
              Oct 22 '10 at 19:45











              0














              The command locate *.orig | xargs rm does work actually but what was happening was that locate was finding *.orig files in the trash can and rm spits out the error No such file or directory when trying to delete files in the trash can.






              share|improve this answer
























              • You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.

                – enzotib
                Oct 23 '10 at 5:57











              • It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.

                – soldier.moth
                Oct 23 '10 at 6:25
















              0














              The command locate *.orig | xargs rm does work actually but what was happening was that locate was finding *.orig files in the trash can and rm spits out the error No such file or directory when trying to delete files in the trash can.






              share|improve this answer
























              • You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.

                – enzotib
                Oct 23 '10 at 5:57











              • It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.

                – soldier.moth
                Oct 23 '10 at 6:25














              0












              0








              0







              The command locate *.orig | xargs rm does work actually but what was happening was that locate was finding *.orig files in the trash can and rm spits out the error No such file or directory when trying to delete files in the trash can.






              share|improve this answer













              The command locate *.orig | xargs rm does work actually but what was happening was that locate was finding *.orig files in the trash can and rm spits out the error No such file or directory when trying to delete files in the trash can.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 22 '10 at 21:20









              soldier.mothsoldier.moth

              132111




              132111













              • You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.

                – enzotib
                Oct 23 '10 at 5:57











              • It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.

                – soldier.moth
                Oct 23 '10 at 6:25



















              • You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.

                – enzotib
                Oct 23 '10 at 5:57











              • It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.

                – soldier.moth
                Oct 23 '10 at 6:25

















              You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.

              – enzotib
              Oct 23 '10 at 5:57





              You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.

              – enzotib
              Oct 23 '10 at 5:57













              It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.

              – soldier.moth
              Oct 23 '10 at 6:25





              It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.

              – soldier.moth
              Oct 23 '10 at 6:25











              0














              locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.



              Just use



              locate .orig


              and if that gets you what you need



              locate .orig | xargs rm


              or, as enzotib mentioned



              locate -0 .orig | xargs -0 rm


              if you have Whitespace in the filenames.






              share|improve this answer




























                0














                locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.



                Just use



                locate .orig


                and if that gets you what you need



                locate .orig | xargs rm


                or, as enzotib mentioned



                locate -0 .orig | xargs -0 rm


                if you have Whitespace in the filenames.






                share|improve this answer


























                  0












                  0








                  0







                  locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.



                  Just use



                  locate .orig


                  and if that gets you what you need



                  locate .orig | xargs rm


                  or, as enzotib mentioned



                  locate -0 .orig | xargs -0 rm


                  if you have Whitespace in the filenames.






                  share|improve this answer













                  locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.



                  Just use



                  locate .orig


                  and if that gets you what you need



                  locate .orig | xargs rm


                  or, as enzotib mentioned



                  locate -0 .orig | xargs -0 rm


                  if you have Whitespace in the filenames.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 20 '11 at 0:11









                  user unknownuser unknown

                  4,87122151




                  4,87122151























                      0














                      A trick : Save all paths in tmp file . then , Loop on it:



                      #!/bin/bash
                      locate .orig /tmp/tmp.txt
                      while read line
                      do
                      pth=$line
                      rm "$pth"
                      done < /tmp/tmp.txt

                      rm -rf /tmp/tmp.txt





                      share|improve this answer




























                        0














                        A trick : Save all paths in tmp file . then , Loop on it:



                        #!/bin/bash
                        locate .orig /tmp/tmp.txt
                        while read line
                        do
                        pth=$line
                        rm "$pth"
                        done < /tmp/tmp.txt

                        rm -rf /tmp/tmp.txt





                        share|improve this answer


























                          0












                          0








                          0







                          A trick : Save all paths in tmp file . then , Loop on it:



                          #!/bin/bash
                          locate .orig /tmp/tmp.txt
                          while read line
                          do
                          pth=$line
                          rm "$pth"
                          done < /tmp/tmp.txt

                          rm -rf /tmp/tmp.txt





                          share|improve this answer













                          A trick : Save all paths in tmp file . then , Loop on it:



                          #!/bin/bash
                          locate .orig /tmp/tmp.txt
                          while read line
                          do
                          pth=$line
                          rm "$pth"
                          done < /tmp/tmp.txt

                          rm -rf /tmp/tmp.txt






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 23 '14 at 18:29









                          Abdennour TOUMIAbdennour TOUMI

                          5,09743345




                          5,09743345






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • 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%2faskubuntu.com%2fquestions%2f8933%2fpipe-results-of-locate-into-rm%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

                              Quarter-circle Tiles

                              build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                              Mont Emei