Have rm not report when a file is missing?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
14
down vote

favorite
1












I have a bash script that I want to remove files from various directories. Frequently, they won't be there because they weren't generated and that's fine. Is there a way to get the script not to report that error, but if rm has some other output to report that?



Alternately, is there a better command to use to remove the file that'll be less noisy?










share|improve this question



























    up vote
    14
    down vote

    favorite
    1












    I have a bash script that I want to remove files from various directories. Frequently, they won't be there because they weren't generated and that's fine. Is there a way to get the script not to report that error, but if rm has some other output to report that?



    Alternately, is there a better command to use to remove the file that'll be less noisy?










    share|improve this question

























      up vote
      14
      down vote

      favorite
      1









      up vote
      14
      down vote

      favorite
      1






      1





      I have a bash script that I want to remove files from various directories. Frequently, they won't be there because they weren't generated and that's fine. Is there a way to get the script not to report that error, but if rm has some other output to report that?



      Alternately, is there a better command to use to remove the file that'll be less noisy?










      share|improve this question















      I have a bash script that I want to remove files from various directories. Frequently, they won't be there because they weren't generated and that's fine. Is there a way to get the script not to report that error, but if rm has some other output to report that?



      Alternately, is there a better command to use to remove the file that'll be less noisy?







      rm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 30 '16 at 13:54









      Braiam

      22.6k1972133




      22.6k1972133










      asked Apr 29 '16 at 18:40









      flickerfly

      3011310




      3011310




















          8 Answers
          8






          active

          oldest

          votes

















          up vote
          32
          down vote



          accepted










          Use the -f option. It will silently ignore nonexistent files.



          From man rm:



           -f, --force
          ignore nonexistent files and arguments, never prompt


          [The "never prompt" part means that (a) -f overrides any previously specified -i or -I option, and (b) write-protected files will be deleted without asking.]



          Example



          Without -f, rm will complain about missing files:



          $ rm nonesuch
          rm: cannot remove ‘nonesuch’: No such file or directory


          With -f, it will be silent:



          $ rm -f nonesuch
          $





          share|improve this answer


















          • 4




            Oh, I new that didn't prompt for removal, didn't realize it also ignored nonexistents. I totally skipped over that when looking at man. :-) Thank you. I'll mark this as the answer soon as I'm allowed.
            – flickerfly
            Apr 29 '16 at 18:54

















          up vote
          7
          down vote













          You stated that you still want to see other output from the rm command when you run it, but using the -f option will suppress those. You will need to filter STDERR for what you want, which is a little tricky, given you want everything else to show.



          You will want to use a command like this:



          rm -f filename 3>&1 1>&2 2>&3 3>&- | grep -v 'No such file or directory'


          Command explained:




          • -f argument is to force through and not prompt for confirmation or errors


          • 3>&1 1>&2 2>&3 3>&- is to switch around STDOUT and STDERR for filtering (you can read more about this here if wanted


          • | grep -v 'No such file or directory' is filtering out the message you do not want to see

          Now, if you just wanted to suppress error messages entirely, you could run the following command:



          rm filename 2> /dev/null


          This command redirects STDERR to /dev/null so you will not see it when you run the command.






          share|improve this answer


















          • 1




            (AFAICS) rm without -v never outputs to stdout, only stderr, so in this case you could just 2>&1 | grep without the dance which is useful more generally,
            – dave_thompson_085
            Apr 30 '16 at 11:20


















          up vote
          7
          down vote













          If your requirement is that rm does not complain about missing files, but that you also want any other output from rm, my suggestion would be to first test for the target file's existence, and only call rm (without the -f flag) if the file actually exists.



          # rest of script
          # ...
          [ -e "$file" ] && rm "$file"
          # ...
          # rest of script


          Calling rm -f on a file that, for example, doesn't have user-write permissions, will remove the file and also not emit the normal prompt for that scenario.



          In case you wanted to use the same idea with multiple files, I would create a function definition, like:



          qrm() 
          for f
          do
          [ -e "$f" ] && rm "$f"
          done



          Use it like: qrm file1 file2-does-not-exist *.txt etc here






          share|improve this answer


















          • 1




            It's worth being aware of the very slight chance of a race condition where the file is deleted (or created) between the test and the removal, but I can't imagine that being relevant in any typical situation where one would be using a shell script.
            – David Z
            May 1 '16 at 7:43


















          up vote
          4
          down vote













          As an alternative, you can use the find command with the -delete option. This will (obviously) only delete the files it finds so it never warns if none are. An example might be:



          find /var/log/triffids/ -name "*.log" -mtime 30 -delete


          which would search the /var/log/triffids/ directory and delete all files with the .log suffix which have not been modified for more than 30 days.



          It is always a good idea to run these commands without the -delete option first, to make sure it's finding the files you expect.






          share|improve this answer






















          • I like this option and will consider a change. Thanks for sharing it.
            – flickerfly
            Apr 30 '16 at 18:19

















          up vote
          3
          down vote













          Check the --force (-f) option of rm:




          -f, --force



          ignore nonexistent files and arguments, never prompt







          share|improve this answer



























            up vote
            2
            down vote













            This is a hack, but you could always touch the file about to be removed. If it doesn't exist, it will be created so rm can remove it.






            share|improve this answer




















            • I like this, except for the performance - how costly is it to touch several K's of files as opposed to only deleting the ones that don't exist?
              – Dani_l
              May 1 '16 at 15:12

















            up vote
            0
            down vote













            You can use -f as it will, according to the man page:




            Attempt to remove the files without prompting for
            confirmation, regardless of the file's permissions. If the file does
            not exist, do not display a diagnostic message or modify the exit
            status to reflect an error. also remember The -f option overrides any
            previous -i options.




            rm -f xyz-directory


            will not prompt you anything, and will do exactly what you want.






            share|improve this answer





























              up vote
              -1
              down vote













              There are two main ways: If you add the -f option, it will not show the "doesn't exist" error and two: (works for almost any command) instead of just doing "thecommand" do "thecommand 2>/dev/null" where "thecommand" is the command you're doing.






              share|improve this answer


















              • 1




                I was avoiding the piping because I don't want to loose other errors that might come up. I don't know what they would be.
                – flickerfly
                Apr 29 '16 at 18:55










              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f280067%2fhave-rm-not-report-when-a-file-is-missing%23new-answer', 'question_page');

              );

              Post as a guest






























              8 Answers
              8






              active

              oldest

              votes








              8 Answers
              8






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              32
              down vote



              accepted










              Use the -f option. It will silently ignore nonexistent files.



              From man rm:



               -f, --force
              ignore nonexistent files and arguments, never prompt


              [The "never prompt" part means that (a) -f overrides any previously specified -i or -I option, and (b) write-protected files will be deleted without asking.]



              Example



              Without -f, rm will complain about missing files:



              $ rm nonesuch
              rm: cannot remove ‘nonesuch’: No such file or directory


              With -f, it will be silent:



              $ rm -f nonesuch
              $





              share|improve this answer


















              • 4




                Oh, I new that didn't prompt for removal, didn't realize it also ignored nonexistents. I totally skipped over that when looking at man. :-) Thank you. I'll mark this as the answer soon as I'm allowed.
                – flickerfly
                Apr 29 '16 at 18:54














              up vote
              32
              down vote



              accepted










              Use the -f option. It will silently ignore nonexistent files.



              From man rm:



               -f, --force
              ignore nonexistent files and arguments, never prompt


              [The "never prompt" part means that (a) -f overrides any previously specified -i or -I option, and (b) write-protected files will be deleted without asking.]



              Example



              Without -f, rm will complain about missing files:



              $ rm nonesuch
              rm: cannot remove ‘nonesuch’: No such file or directory


              With -f, it will be silent:



              $ rm -f nonesuch
              $





              share|improve this answer


















              • 4




                Oh, I new that didn't prompt for removal, didn't realize it also ignored nonexistents. I totally skipped over that when looking at man. :-) Thank you. I'll mark this as the answer soon as I'm allowed.
                – flickerfly
                Apr 29 '16 at 18:54












              up vote
              32
              down vote



              accepted







              up vote
              32
              down vote



              accepted






              Use the -f option. It will silently ignore nonexistent files.



              From man rm:



               -f, --force
              ignore nonexistent files and arguments, never prompt


              [The "never prompt" part means that (a) -f overrides any previously specified -i or -I option, and (b) write-protected files will be deleted without asking.]



              Example



              Without -f, rm will complain about missing files:



              $ rm nonesuch
              rm: cannot remove ‘nonesuch’: No such file or directory


              With -f, it will be silent:



              $ rm -f nonesuch
              $





              share|improve this answer














              Use the -f option. It will silently ignore nonexistent files.



              From man rm:



               -f, --force
              ignore nonexistent files and arguments, never prompt


              [The "never prompt" part means that (a) -f overrides any previously specified -i or -I option, and (b) write-protected files will be deleted without asking.]



              Example



              Without -f, rm will complain about missing files:



              $ rm nonesuch
              rm: cannot remove ‘nonesuch’: No such file or directory


              With -f, it will be silent:



              $ rm -f nonesuch
              $






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 29 '16 at 19:01

























              answered Apr 29 '16 at 18:44









              John1024

              44.7k4101117




              44.7k4101117







              • 4




                Oh, I new that didn't prompt for removal, didn't realize it also ignored nonexistents. I totally skipped over that when looking at man. :-) Thank you. I'll mark this as the answer soon as I'm allowed.
                – flickerfly
                Apr 29 '16 at 18:54












              • 4




                Oh, I new that didn't prompt for removal, didn't realize it also ignored nonexistents. I totally skipped over that when looking at man. :-) Thank you. I'll mark this as the answer soon as I'm allowed.
                – flickerfly
                Apr 29 '16 at 18:54







              4




              4




              Oh, I new that didn't prompt for removal, didn't realize it also ignored nonexistents. I totally skipped over that when looking at man. :-) Thank you. I'll mark this as the answer soon as I'm allowed.
              – flickerfly
              Apr 29 '16 at 18:54




              Oh, I new that didn't prompt for removal, didn't realize it also ignored nonexistents. I totally skipped over that when looking at man. :-) Thank you. I'll mark this as the answer soon as I'm allowed.
              – flickerfly
              Apr 29 '16 at 18:54












              up vote
              7
              down vote













              You stated that you still want to see other output from the rm command when you run it, but using the -f option will suppress those. You will need to filter STDERR for what you want, which is a little tricky, given you want everything else to show.



              You will want to use a command like this:



              rm -f filename 3>&1 1>&2 2>&3 3>&- | grep -v 'No such file or directory'


              Command explained:




              • -f argument is to force through and not prompt for confirmation or errors


              • 3>&1 1>&2 2>&3 3>&- is to switch around STDOUT and STDERR for filtering (you can read more about this here if wanted


              • | grep -v 'No such file or directory' is filtering out the message you do not want to see

              Now, if you just wanted to suppress error messages entirely, you could run the following command:



              rm filename 2> /dev/null


              This command redirects STDERR to /dev/null so you will not see it when you run the command.






              share|improve this answer


















              • 1




                (AFAICS) rm without -v never outputs to stdout, only stderr, so in this case you could just 2>&1 | grep without the dance which is useful more generally,
                – dave_thompson_085
                Apr 30 '16 at 11:20















              up vote
              7
              down vote













              You stated that you still want to see other output from the rm command when you run it, but using the -f option will suppress those. You will need to filter STDERR for what you want, which is a little tricky, given you want everything else to show.



              You will want to use a command like this:



              rm -f filename 3>&1 1>&2 2>&3 3>&- | grep -v 'No such file or directory'


              Command explained:




              • -f argument is to force through and not prompt for confirmation or errors


              • 3>&1 1>&2 2>&3 3>&- is to switch around STDOUT and STDERR for filtering (you can read more about this here if wanted


              • | grep -v 'No such file or directory' is filtering out the message you do not want to see

              Now, if you just wanted to suppress error messages entirely, you could run the following command:



              rm filename 2> /dev/null


              This command redirects STDERR to /dev/null so you will not see it when you run the command.






              share|improve this answer


















              • 1




                (AFAICS) rm without -v never outputs to stdout, only stderr, so in this case you could just 2>&1 | grep without the dance which is useful more generally,
                – dave_thompson_085
                Apr 30 '16 at 11:20













              up vote
              7
              down vote










              up vote
              7
              down vote









              You stated that you still want to see other output from the rm command when you run it, but using the -f option will suppress those. You will need to filter STDERR for what you want, which is a little tricky, given you want everything else to show.



              You will want to use a command like this:



              rm -f filename 3>&1 1>&2 2>&3 3>&- | grep -v 'No such file or directory'


              Command explained:




              • -f argument is to force through and not prompt for confirmation or errors


              • 3>&1 1>&2 2>&3 3>&- is to switch around STDOUT and STDERR for filtering (you can read more about this here if wanted


              • | grep -v 'No such file or directory' is filtering out the message you do not want to see

              Now, if you just wanted to suppress error messages entirely, you could run the following command:



              rm filename 2> /dev/null


              This command redirects STDERR to /dev/null so you will not see it when you run the command.






              share|improve this answer














              You stated that you still want to see other output from the rm command when you run it, but using the -f option will suppress those. You will need to filter STDERR for what you want, which is a little tricky, given you want everything else to show.



              You will want to use a command like this:



              rm -f filename 3>&1 1>&2 2>&3 3>&- | grep -v 'No such file or directory'


              Command explained:




              • -f argument is to force through and not prompt for confirmation or errors


              • 3>&1 1>&2 2>&3 3>&- is to switch around STDOUT and STDERR for filtering (you can read more about this here if wanted


              • | grep -v 'No such file or directory' is filtering out the message you do not want to see

              Now, if you just wanted to suppress error messages entirely, you could run the following command:



              rm filename 2> /dev/null


              This command redirects STDERR to /dev/null so you will not see it when you run the command.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 30 '16 at 5:54









              muru

              34k578147




              34k578147










              answered Apr 29 '16 at 18:56









              BriGuy

              2,3011819




              2,3011819







              • 1




                (AFAICS) rm without -v never outputs to stdout, only stderr, so in this case you could just 2>&1 | grep without the dance which is useful more generally,
                – dave_thompson_085
                Apr 30 '16 at 11:20













              • 1




                (AFAICS) rm without -v never outputs to stdout, only stderr, so in this case you could just 2>&1 | grep without the dance which is useful more generally,
                – dave_thompson_085
                Apr 30 '16 at 11:20








              1




              1




              (AFAICS) rm without -v never outputs to stdout, only stderr, so in this case you could just 2>&1 | grep without the dance which is useful more generally,
              – dave_thompson_085
              Apr 30 '16 at 11:20





              (AFAICS) rm without -v never outputs to stdout, only stderr, so in this case you could just 2>&1 | grep without the dance which is useful more generally,
              – dave_thompson_085
              Apr 30 '16 at 11:20











              up vote
              7
              down vote













              If your requirement is that rm does not complain about missing files, but that you also want any other output from rm, my suggestion would be to first test for the target file's existence, and only call rm (without the -f flag) if the file actually exists.



              # rest of script
              # ...
              [ -e "$file" ] && rm "$file"
              # ...
              # rest of script


              Calling rm -f on a file that, for example, doesn't have user-write permissions, will remove the file and also not emit the normal prompt for that scenario.



              In case you wanted to use the same idea with multiple files, I would create a function definition, like:



              qrm() 
              for f
              do
              [ -e "$f" ] && rm "$f"
              done



              Use it like: qrm file1 file2-does-not-exist *.txt etc here






              share|improve this answer


















              • 1




                It's worth being aware of the very slight chance of a race condition where the file is deleted (or created) between the test and the removal, but I can't imagine that being relevant in any typical situation where one would be using a shell script.
                – David Z
                May 1 '16 at 7:43















              up vote
              7
              down vote













              If your requirement is that rm does not complain about missing files, but that you also want any other output from rm, my suggestion would be to first test for the target file's existence, and only call rm (without the -f flag) if the file actually exists.



              # rest of script
              # ...
              [ -e "$file" ] && rm "$file"
              # ...
              # rest of script


              Calling rm -f on a file that, for example, doesn't have user-write permissions, will remove the file and also not emit the normal prompt for that scenario.



              In case you wanted to use the same idea with multiple files, I would create a function definition, like:



              qrm() 
              for f
              do
              [ -e "$f" ] && rm "$f"
              done



              Use it like: qrm file1 file2-does-not-exist *.txt etc here






              share|improve this answer


















              • 1




                It's worth being aware of the very slight chance of a race condition where the file is deleted (or created) between the test and the removal, but I can't imagine that being relevant in any typical situation where one would be using a shell script.
                – David Z
                May 1 '16 at 7:43













              up vote
              7
              down vote










              up vote
              7
              down vote









              If your requirement is that rm does not complain about missing files, but that you also want any other output from rm, my suggestion would be to first test for the target file's existence, and only call rm (without the -f flag) if the file actually exists.



              # rest of script
              # ...
              [ -e "$file" ] && rm "$file"
              # ...
              # rest of script


              Calling rm -f on a file that, for example, doesn't have user-write permissions, will remove the file and also not emit the normal prompt for that scenario.



              In case you wanted to use the same idea with multiple files, I would create a function definition, like:



              qrm() 
              for f
              do
              [ -e "$f" ] && rm "$f"
              done



              Use it like: qrm file1 file2-does-not-exist *.txt etc here






              share|improve this answer














              If your requirement is that rm does not complain about missing files, but that you also want any other output from rm, my suggestion would be to first test for the target file's existence, and only call rm (without the -f flag) if the file actually exists.



              # rest of script
              # ...
              [ -e "$file" ] && rm "$file"
              # ...
              # rest of script


              Calling rm -f on a file that, for example, doesn't have user-write permissions, will remove the file and also not emit the normal prompt for that scenario.



              In case you wanted to use the same idea with multiple files, I would create a function definition, like:



              qrm() 
              for f
              do
              [ -e "$f" ] && rm "$f"
              done



              Use it like: qrm file1 file2-does-not-exist *.txt etc here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 1 '16 at 15:04

























              answered Apr 30 '16 at 0:29









              Jeff Schaller

              33.8k851113




              33.8k851113







              • 1




                It's worth being aware of the very slight chance of a race condition where the file is deleted (or created) between the test and the removal, but I can't imagine that being relevant in any typical situation where one would be using a shell script.
                – David Z
                May 1 '16 at 7:43













              • 1




                It's worth being aware of the very slight chance of a race condition where the file is deleted (or created) between the test and the removal, but I can't imagine that being relevant in any typical situation where one would be using a shell script.
                – David Z
                May 1 '16 at 7:43








              1




              1




              It's worth being aware of the very slight chance of a race condition where the file is deleted (or created) between the test and the removal, but I can't imagine that being relevant in any typical situation where one would be using a shell script.
              – David Z
              May 1 '16 at 7:43





              It's worth being aware of the very slight chance of a race condition where the file is deleted (or created) between the test and the removal, but I can't imagine that being relevant in any typical situation where one would be using a shell script.
              – David Z
              May 1 '16 at 7:43











              up vote
              4
              down vote













              As an alternative, you can use the find command with the -delete option. This will (obviously) only delete the files it finds so it never warns if none are. An example might be:



              find /var/log/triffids/ -name "*.log" -mtime 30 -delete


              which would search the /var/log/triffids/ directory and delete all files with the .log suffix which have not been modified for more than 30 days.



              It is always a good idea to run these commands without the -delete option first, to make sure it's finding the files you expect.






              share|improve this answer






















              • I like this option and will consider a change. Thanks for sharing it.
                – flickerfly
                Apr 30 '16 at 18:19














              up vote
              4
              down vote













              As an alternative, you can use the find command with the -delete option. This will (obviously) only delete the files it finds so it never warns if none are. An example might be:



              find /var/log/triffids/ -name "*.log" -mtime 30 -delete


              which would search the /var/log/triffids/ directory and delete all files with the .log suffix which have not been modified for more than 30 days.



              It is always a good idea to run these commands without the -delete option first, to make sure it's finding the files you expect.






              share|improve this answer






















              • I like this option and will consider a change. Thanks for sharing it.
                – flickerfly
                Apr 30 '16 at 18:19












              up vote
              4
              down vote










              up vote
              4
              down vote









              As an alternative, you can use the find command with the -delete option. This will (obviously) only delete the files it finds so it never warns if none are. An example might be:



              find /var/log/triffids/ -name "*.log" -mtime 30 -delete


              which would search the /var/log/triffids/ directory and delete all files with the .log suffix which have not been modified for more than 30 days.



              It is always a good idea to run these commands without the -delete option first, to make sure it's finding the files you expect.






              share|improve this answer














              As an alternative, you can use the find command with the -delete option. This will (obviously) only delete the files it finds so it never warns if none are. An example might be:



              find /var/log/triffids/ -name "*.log" -mtime 30 -delete


              which would search the /var/log/triffids/ directory and delete all files with the .log suffix which have not been modified for more than 30 days.



              It is always a good idea to run these commands without the -delete option first, to make sure it's finding the files you expect.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 30 '16 at 18:21

























              answered Apr 30 '16 at 18:17









              seumasmac

              1,343710




              1,343710











              • I like this option and will consider a change. Thanks for sharing it.
                – flickerfly
                Apr 30 '16 at 18:19
















              • I like this option and will consider a change. Thanks for sharing it.
                – flickerfly
                Apr 30 '16 at 18:19















              I like this option and will consider a change. Thanks for sharing it.
              – flickerfly
              Apr 30 '16 at 18:19




              I like this option and will consider a change. Thanks for sharing it.
              – flickerfly
              Apr 30 '16 at 18:19










              up vote
              3
              down vote













              Check the --force (-f) option of rm:




              -f, --force



              ignore nonexistent files and arguments, never prompt







              share|improve this answer
























                up vote
                3
                down vote













                Check the --force (-f) option of rm:




                -f, --force



                ignore nonexistent files and arguments, never prompt







                share|improve this answer






















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  Check the --force (-f) option of rm:




                  -f, --force



                  ignore nonexistent files and arguments, never prompt







                  share|improve this answer












                  Check the --force (-f) option of rm:




                  -f, --force



                  ignore nonexistent files and arguments, never prompt








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 29 '16 at 18:44









                  heemayl

                  33.6k36999




                  33.6k36999




















                      up vote
                      2
                      down vote













                      This is a hack, but you could always touch the file about to be removed. If it doesn't exist, it will be created so rm can remove it.






                      share|improve this answer




















                      • I like this, except for the performance - how costly is it to touch several K's of files as opposed to only deleting the ones that don't exist?
                        – Dani_l
                        May 1 '16 at 15:12














                      up vote
                      2
                      down vote













                      This is a hack, but you could always touch the file about to be removed. If it doesn't exist, it will be created so rm can remove it.






                      share|improve this answer




















                      • I like this, except for the performance - how costly is it to touch several K's of files as opposed to only deleting the ones that don't exist?
                        – Dani_l
                        May 1 '16 at 15:12












                      up vote
                      2
                      down vote










                      up vote
                      2
                      down vote









                      This is a hack, but you could always touch the file about to be removed. If it doesn't exist, it will be created so rm can remove it.






                      share|improve this answer












                      This is a hack, but you could always touch the file about to be removed. If it doesn't exist, it will be created so rm can remove it.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 30 '16 at 9:05









                      matega

                      1212




                      1212











                      • I like this, except for the performance - how costly is it to touch several K's of files as opposed to only deleting the ones that don't exist?
                        – Dani_l
                        May 1 '16 at 15:12
















                      • I like this, except for the performance - how costly is it to touch several K's of files as opposed to only deleting the ones that don't exist?
                        – Dani_l
                        May 1 '16 at 15:12















                      I like this, except for the performance - how costly is it to touch several K's of files as opposed to only deleting the ones that don't exist?
                      – Dani_l
                      May 1 '16 at 15:12




                      I like this, except for the performance - how costly is it to touch several K's of files as opposed to only deleting the ones that don't exist?
                      – Dani_l
                      May 1 '16 at 15:12










                      up vote
                      0
                      down vote













                      You can use -f as it will, according to the man page:




                      Attempt to remove the files without prompting for
                      confirmation, regardless of the file's permissions. If the file does
                      not exist, do not display a diagnostic message or modify the exit
                      status to reflect an error. also remember The -f option overrides any
                      previous -i options.




                      rm -f xyz-directory


                      will not prompt you anything, and will do exactly what you want.






                      share|improve this answer


























                        up vote
                        0
                        down vote













                        You can use -f as it will, according to the man page:




                        Attempt to remove the files without prompting for
                        confirmation, regardless of the file's permissions. If the file does
                        not exist, do not display a diagnostic message or modify the exit
                        status to reflect an error. also remember The -f option overrides any
                        previous -i options.




                        rm -f xyz-directory


                        will not prompt you anything, and will do exactly what you want.






                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You can use -f as it will, according to the man page:




                          Attempt to remove the files without prompting for
                          confirmation, regardless of the file's permissions. If the file does
                          not exist, do not display a diagnostic message or modify the exit
                          status to reflect an error. also remember The -f option overrides any
                          previous -i options.




                          rm -f xyz-directory


                          will not prompt you anything, and will do exactly what you want.






                          share|improve this answer














                          You can use -f as it will, according to the man page:




                          Attempt to remove the files without prompting for
                          confirmation, regardless of the file's permissions. If the file does
                          not exist, do not display a diagnostic message or modify the exit
                          status to reflect an error. also remember The -f option overrides any
                          previous -i options.




                          rm -f xyz-directory


                          will not prompt you anything, and will do exactly what you want.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Apr 30 '16 at 19:54









                          garethTheRed

                          23.3k35978




                          23.3k35978










                          answered Apr 30 '16 at 19:09









                          Ankit Jain

                          13




                          13




















                              up vote
                              -1
                              down vote













                              There are two main ways: If you add the -f option, it will not show the "doesn't exist" error and two: (works for almost any command) instead of just doing "thecommand" do "thecommand 2>/dev/null" where "thecommand" is the command you're doing.






                              share|improve this answer


















                              • 1




                                I was avoiding the piping because I don't want to loose other errors that might come up. I don't know what they would be.
                                – flickerfly
                                Apr 29 '16 at 18:55














                              up vote
                              -1
                              down vote













                              There are two main ways: If you add the -f option, it will not show the "doesn't exist" error and two: (works for almost any command) instead of just doing "thecommand" do "thecommand 2>/dev/null" where "thecommand" is the command you're doing.






                              share|improve this answer


















                              • 1




                                I was avoiding the piping because I don't want to loose other errors that might come up. I don't know what they would be.
                                – flickerfly
                                Apr 29 '16 at 18:55












                              up vote
                              -1
                              down vote










                              up vote
                              -1
                              down vote









                              There are two main ways: If you add the -f option, it will not show the "doesn't exist" error and two: (works for almost any command) instead of just doing "thecommand" do "thecommand 2>/dev/null" where "thecommand" is the command you're doing.






                              share|improve this answer














                              There are two main ways: If you add the -f option, it will not show the "doesn't exist" error and two: (works for almost any command) instead of just doing "thecommand" do "thecommand 2>/dev/null" where "thecommand" is the command you're doing.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited May 1 '16 at 22:29


























                              community wiki





                              3 revs
                              John








                              • 1




                                I was avoiding the piping because I don't want to loose other errors that might come up. I don't know what they would be.
                                – flickerfly
                                Apr 29 '16 at 18:55












                              • 1




                                I was avoiding the piping because I don't want to loose other errors that might come up. I don't know what they would be.
                                – flickerfly
                                Apr 29 '16 at 18:55







                              1




                              1




                              I was avoiding the piping because I don't want to loose other errors that might come up. I don't know what they would be.
                              – flickerfly
                              Apr 29 '16 at 18:55




                              I was avoiding the piping because I don't want to loose other errors that might come up. I don't know what they would be.
                              – flickerfly
                              Apr 29 '16 at 18:55

















                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f280067%2fhave-rm-not-report-when-a-file-is-missing%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Bahrain

                              Postfix configuration issue with fips on centos 7; mailgun relay