Delete multiple files on PowerShell command line












17















With PowerShell, what is the most concise way to delete multiple explicitly named files?



E.g. on *ix it would be:



rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif


I'm currently using:



echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


But I consider it suboptimal, so I would like to see alternatives.










share|improve this question





























    17















    With PowerShell, what is the most concise way to delete multiple explicitly named files?



    E.g. on *ix it would be:



    rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif


    I'm currently using:



    echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


    But I consider it suboptimal, so I would like to see alternatives.










    share|improve this question



























      17












      17








      17


      2






      With PowerShell, what is the most concise way to delete multiple explicitly named files?



      E.g. on *ix it would be:



      rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif


      I'm currently using:



      echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


      But I consider it suboptimal, so I would like to see alternatives.










      share|improve this question
















      With PowerShell, what is the most concise way to delete multiple explicitly named files?



      E.g. on *ix it would be:



      rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif


      I'm currently using:



      echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


      But I consider it suboptimal, so I would like to see alternatives.







      powershell file-management






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 8 '17 at 14:43









      djsmiley2k

      5,11612336




      5,11612336










      asked Dec 16 '11 at 23:57









      Matthew FlaschenMatthew Flaschen

      2,18411426




      2,18411426






















          3 Answers
          3






          active

          oldest

          votes


















          24














          You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.



          rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif


          Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.






          share|improve this answer

































            3














            This is what I ended up using:



            echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


            This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.






            share|improve this answer

































              0














              Old dog's trick, define an array first.
              Put your stuff in it, and RM the heck out of it.



              $myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
              rm $myArray





              share|improve this answer























                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "3"
                };
                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%2fsuperuser.com%2fquestions%2f368830%2fdelete-multiple-files-on-powershell-command-line%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                24














                You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.



                rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif


                Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.






                share|improve this answer






























                  24














                  You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.



                  rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif


                  Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.






                  share|improve this answer




























                    24












                    24








                    24







                    You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.



                    rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif


                    Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.






                    share|improve this answer















                    You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.



                    rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif


                    Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 15 at 18:31

























                    answered Dec 17 '11 at 0:40









                    William JacksonWilliam Jackson

                    7,29312843




                    7,29312843

























                        3














                        This is what I ended up using:



                        echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


                        This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.






                        share|improve this answer






























                          3














                          This is what I ended up using:



                          echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


                          This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.






                          share|improve this answer




























                            3












                            3








                            3







                            This is what I ended up using:



                            echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


                            This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.






                            share|improve this answer















                            This is what I ended up using:



                            echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm


                            This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 21 '11 at 12:39









                            Sathyajith Bhat

                            52.9k29156252




                            52.9k29156252










                            answered Dec 16 '11 at 23:57









                            Matthew FlaschenMatthew Flaschen

                            2,18411426




                            2,18411426























                                0














                                Old dog's trick, define an array first.
                                Put your stuff in it, and RM the heck out of it.



                                $myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
                                rm $myArray





                                share|improve this answer




























                                  0














                                  Old dog's trick, define an array first.
                                  Put your stuff in it, and RM the heck out of it.



                                  $myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
                                  rm $myArray





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    Old dog's trick, define an array first.
                                    Put your stuff in it, and RM the heck out of it.



                                    $myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
                                    rm $myArray





                                    share|improve this answer













                                    Old dog's trick, define an array first.
                                    Put your stuff in it, and RM the heck out of it.



                                    $myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
                                    rm $myArray






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 25 '17 at 17:31









                                    JP LizotteJP Lizotte

                                    1




                                    1






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Super User!


                                        • 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%2fsuperuser.com%2fquestions%2f368830%2fdelete-multiple-files-on-powershell-command-line%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

                                        Paul Cézanne

                                        UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                                        Angular material date-picker (MatDatepicker) auto completes the date on focus out