Remove files that start with but don't contain

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











up vote
1
down vote

favorite












I'm trying to remove a lot of files at once but need to be specific as to not remove any of the files I actually need.



I have a ton of corrupt files that start master- but there are valid files that start with master-2018



So, I want to do something like



rm -rf master-* --exclude master-2018*


Is that I need possible?










share|improve this question









New contributor




Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    1
    down vote

    favorite












    I'm trying to remove a lot of files at once but need to be specific as to not remove any of the files I actually need.



    I have a ton of corrupt files that start master- but there are valid files that start with master-2018



    So, I want to do something like



    rm -rf master-* --exclude master-2018*


    Is that I need possible?










    share|improve this question









    New contributor




    Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm trying to remove a lot of files at once but need to be specific as to not remove any of the files I actually need.



      I have a ton of corrupt files that start master- but there are valid files that start with master-2018



      So, I want to do something like



      rm -rf master-* --exclude master-2018*


      Is that I need possible?










      share|improve this question









      New contributor




      Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm trying to remove a lot of files at once but need to be specific as to not remove any of the files I actually need.



      I have a ton of corrupt files that start master- but there are valid files that start with master-2018



      So, I want to do something like



      rm -rf master-* --exclude master-2018*


      Is that I need possible?







      linux filenames rm






      share|improve this question









      New contributor




      Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 1 hour ago









      Jeff Schaller

      35.2k952115




      35.2k952115






      New contributor




      Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      Dan James Palmer

      1084




      1084




      New contributor




      Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Dan James Palmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Yes you can use more than one pattern with find:



          $ find -name 'master*' ! -name 'master-2018*' -print0 |
          xargs -0 echo rm -fr


          (remove the echo if you're satisfied with the dry run)



          You should add a -maxdepth 1 predicate just after find if you only want ro remove files from the current directory, ie master-1991 but no subdir/master-1991.






          share|improve this answer






















          • but the OP is using rm -rf, -delete will only work if the dir is empty.
            – mosvy
            1 hour ago










          • I'll give this a go and report back, thanks for your help
            – Dan James Palmer
            56 mins ago










          • This worked great, thank you
            – Dan James Palmer
            29 mins ago

















          up vote
          1
          down vote













          In bash:



          shopt -s extglob
          echo rm master-!(2018*)


          Remove the echo if it looks correct.



          The above uses bash's extended globbing facility to match files that start with master- but who do not have 2018 immediately following, then followed by anything (*).






          share|improve this answer



























            up vote
            0
            down vote













            Use find:



            find . ! -name "master-2018*" -delete





            share|improve this answer




















            • Can you specify more than one? Like find . ! -name "master-201801*" "master-201802" -delete
              – Dan James Palmer
              1 hour ago










            • there are other files in the same folder that start with things like test-2018 and find-2018. I don't want to delete any of these. It's strictly files that start master- but not master-2018*
              – Dan James Palmer
              1 hour ago










            • that's broken -- it will try to delete all files that don't start with master-2018, including directories and those that do not start with master.
              – mosvy
              1 hour ago

















            up vote
            0
            down vote













            If all files you want to delete has pattern like master-YYYY*, you can use those patterns:



            rm -rf master-???[0-79]*
            rm -rf master-??[02-9]*
            rm -rf master-?[1-9]*
            rm -rf master-[013-9]*


            The goal is to ommit digits from a year number, so on first place after master- we need to ommit (don't remove) digit 2, on 2nd place digit 0, on 3rd place digit 1, and on 4th place - digit 8
            I tried it just a minute before, and is enough to run only first two of them.



            Second method:
            You can move master-2018 to another dir, e.g. /tmp,
            then remove everything with master-*, and move back your master-2018 from tmp.



            mkdir /tmp/backup
            mv -r master-2018* /tmp/backup
            rm -rf master-*
            mv -r /tmp/backup/* .





            share|improve this answer










            New contributor




            Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.













            • 1




              Ahh so, rm -rf master-????[2019-9999]* would remove all files from master-2019* to master-9999*?
              – Dan James Palmer
              1 hour ago










            • No, it not works this way. You can not specify numbers in [ ] braces. Only digits. You specify which digits will be places in the place of [xxxxxxx]. So max possibilities is range from 0 to 9 like this [0-9] or this [0123456789]. This can replace only one character from file name. rob@vps:mast$ ls master-1990 master-1994 master-2006 master-2010 master-2014 master-2018 master-1991 master-1995 master-2007 master-2009 master-2013 master-2017 rob@vps:mast$ rm master-[2000-2019]* rob@vps:mast$ ls empty directory`
              – Robert Zabkiewicz
              1 hour ago







            • 1




              none of your commands will remove a file with the name master-of-puppets
              – mosvy
              1 hour ago










            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: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            Dan James Palmer is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480241%2fremove-files-that-start-with-but-dont-contain%23new-answer', 'question_page');

            );

            Post as a guest






























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            Yes you can use more than one pattern with find:



            $ find -name 'master*' ! -name 'master-2018*' -print0 |
            xargs -0 echo rm -fr


            (remove the echo if you're satisfied with the dry run)



            You should add a -maxdepth 1 predicate just after find if you only want ro remove files from the current directory, ie master-1991 but no subdir/master-1991.






            share|improve this answer






















            • but the OP is using rm -rf, -delete will only work if the dir is empty.
              – mosvy
              1 hour ago










            • I'll give this a go and report back, thanks for your help
              – Dan James Palmer
              56 mins ago










            • This worked great, thank you
              – Dan James Palmer
              29 mins ago














            up vote
            3
            down vote



            accepted










            Yes you can use more than one pattern with find:



            $ find -name 'master*' ! -name 'master-2018*' -print0 |
            xargs -0 echo rm -fr


            (remove the echo if you're satisfied with the dry run)



            You should add a -maxdepth 1 predicate just after find if you only want ro remove files from the current directory, ie master-1991 but no subdir/master-1991.






            share|improve this answer






















            • but the OP is using rm -rf, -delete will only work if the dir is empty.
              – mosvy
              1 hour ago










            • I'll give this a go and report back, thanks for your help
              – Dan James Palmer
              56 mins ago










            • This worked great, thank you
              – Dan James Palmer
              29 mins ago












            up vote
            3
            down vote



            accepted







            up vote
            3
            down vote



            accepted






            Yes you can use more than one pattern with find:



            $ find -name 'master*' ! -name 'master-2018*' -print0 |
            xargs -0 echo rm -fr


            (remove the echo if you're satisfied with the dry run)



            You should add a -maxdepth 1 predicate just after find if you only want ro remove files from the current directory, ie master-1991 but no subdir/master-1991.






            share|improve this answer














            Yes you can use more than one pattern with find:



            $ find -name 'master*' ! -name 'master-2018*' -print0 |
            xargs -0 echo rm -fr


            (remove the echo if you're satisfied with the dry run)



            You should add a -maxdepth 1 predicate just after find if you only want ro remove files from the current directory, ie master-1991 but no subdir/master-1991.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 51 mins ago

























            answered 1 hour ago









            mosvy

            3,770120




            3,770120











            • but the OP is using rm -rf, -delete will only work if the dir is empty.
              – mosvy
              1 hour ago










            • I'll give this a go and report back, thanks for your help
              – Dan James Palmer
              56 mins ago










            • This worked great, thank you
              – Dan James Palmer
              29 mins ago
















            • but the OP is using rm -rf, -delete will only work if the dir is empty.
              – mosvy
              1 hour ago










            • I'll give this a go and report back, thanks for your help
              – Dan James Palmer
              56 mins ago










            • This worked great, thank you
              – Dan James Palmer
              29 mins ago















            but the OP is using rm -rf, -delete will only work if the dir is empty.
            – mosvy
            1 hour ago




            but the OP is using rm -rf, -delete will only work if the dir is empty.
            – mosvy
            1 hour ago












            I'll give this a go and report back, thanks for your help
            – Dan James Palmer
            56 mins ago




            I'll give this a go and report back, thanks for your help
            – Dan James Palmer
            56 mins ago












            This worked great, thank you
            – Dan James Palmer
            29 mins ago




            This worked great, thank you
            – Dan James Palmer
            29 mins ago












            up vote
            1
            down vote













            In bash:



            shopt -s extglob
            echo rm master-!(2018*)


            Remove the echo if it looks correct.



            The above uses bash's extended globbing facility to match files that start with master- but who do not have 2018 immediately following, then followed by anything (*).






            share|improve this answer
























              up vote
              1
              down vote













              In bash:



              shopt -s extglob
              echo rm master-!(2018*)


              Remove the echo if it looks correct.



              The above uses bash's extended globbing facility to match files that start with master- but who do not have 2018 immediately following, then followed by anything (*).






              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                In bash:



                shopt -s extglob
                echo rm master-!(2018*)


                Remove the echo if it looks correct.



                The above uses bash's extended globbing facility to match files that start with master- but who do not have 2018 immediately following, then followed by anything (*).






                share|improve this answer












                In bash:



                shopt -s extglob
                echo rm master-!(2018*)


                Remove the echo if it looks correct.



                The above uses bash's extended globbing facility to match files that start with master- but who do not have 2018 immediately following, then followed by anything (*).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                Jeff Schaller

                35.2k952115




                35.2k952115




















                    up vote
                    0
                    down vote













                    Use find:



                    find . ! -name "master-2018*" -delete





                    share|improve this answer




















                    • Can you specify more than one? Like find . ! -name "master-201801*" "master-201802" -delete
                      – Dan James Palmer
                      1 hour ago










                    • there are other files in the same folder that start with things like test-2018 and find-2018. I don't want to delete any of these. It's strictly files that start master- but not master-2018*
                      – Dan James Palmer
                      1 hour ago










                    • that's broken -- it will try to delete all files that don't start with master-2018, including directories and those that do not start with master.
                      – mosvy
                      1 hour ago














                    up vote
                    0
                    down vote













                    Use find:



                    find . ! -name "master-2018*" -delete





                    share|improve this answer




















                    • Can you specify more than one? Like find . ! -name "master-201801*" "master-201802" -delete
                      – Dan James Palmer
                      1 hour ago










                    • there are other files in the same folder that start with things like test-2018 and find-2018. I don't want to delete any of these. It's strictly files that start master- but not master-2018*
                      – Dan James Palmer
                      1 hour ago










                    • that's broken -- it will try to delete all files that don't start with master-2018, including directories and those that do not start with master.
                      – mosvy
                      1 hour ago












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Use find:



                    find . ! -name "master-2018*" -delete





                    share|improve this answer












                    Use find:



                    find . ! -name "master-2018*" -delete






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    Ipor Sircer

                    9,8711921




                    9,8711921











                    • Can you specify more than one? Like find . ! -name "master-201801*" "master-201802" -delete
                      – Dan James Palmer
                      1 hour ago










                    • there are other files in the same folder that start with things like test-2018 and find-2018. I don't want to delete any of these. It's strictly files that start master- but not master-2018*
                      – Dan James Palmer
                      1 hour ago










                    • that's broken -- it will try to delete all files that don't start with master-2018, including directories and those that do not start with master.
                      – mosvy
                      1 hour ago
















                    • Can you specify more than one? Like find . ! -name "master-201801*" "master-201802" -delete
                      – Dan James Palmer
                      1 hour ago










                    • there are other files in the same folder that start with things like test-2018 and find-2018. I don't want to delete any of these. It's strictly files that start master- but not master-2018*
                      – Dan James Palmer
                      1 hour ago










                    • that's broken -- it will try to delete all files that don't start with master-2018, including directories and those that do not start with master.
                      – mosvy
                      1 hour ago















                    Can you specify more than one? Like find . ! -name "master-201801*" "master-201802" -delete
                    – Dan James Palmer
                    1 hour ago




                    Can you specify more than one? Like find . ! -name "master-201801*" "master-201802" -delete
                    – Dan James Palmer
                    1 hour ago












                    there are other files in the same folder that start with things like test-2018 and find-2018. I don't want to delete any of these. It's strictly files that start master- but not master-2018*
                    – Dan James Palmer
                    1 hour ago




                    there are other files in the same folder that start with things like test-2018 and find-2018. I don't want to delete any of these. It's strictly files that start master- but not master-2018*
                    – Dan James Palmer
                    1 hour ago












                    that's broken -- it will try to delete all files that don't start with master-2018, including directories and those that do not start with master.
                    – mosvy
                    1 hour ago




                    that's broken -- it will try to delete all files that don't start with master-2018, including directories and those that do not start with master.
                    – mosvy
                    1 hour ago










                    up vote
                    0
                    down vote













                    If all files you want to delete has pattern like master-YYYY*, you can use those patterns:



                    rm -rf master-???[0-79]*
                    rm -rf master-??[02-9]*
                    rm -rf master-?[1-9]*
                    rm -rf master-[013-9]*


                    The goal is to ommit digits from a year number, so on first place after master- we need to ommit (don't remove) digit 2, on 2nd place digit 0, on 3rd place digit 1, and on 4th place - digit 8
                    I tried it just a minute before, and is enough to run only first two of them.



                    Second method:
                    You can move master-2018 to another dir, e.g. /tmp,
                    then remove everything with master-*, and move back your master-2018 from tmp.



                    mkdir /tmp/backup
                    mv -r master-2018* /tmp/backup
                    rm -rf master-*
                    mv -r /tmp/backup/* .





                    share|improve this answer










                    New contributor




                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.













                    • 1




                      Ahh so, rm -rf master-????[2019-9999]* would remove all files from master-2019* to master-9999*?
                      – Dan James Palmer
                      1 hour ago










                    • No, it not works this way. You can not specify numbers in [ ] braces. Only digits. You specify which digits will be places in the place of [xxxxxxx]. So max possibilities is range from 0 to 9 like this [0-9] or this [0123456789]. This can replace only one character from file name. rob@vps:mast$ ls master-1990 master-1994 master-2006 master-2010 master-2014 master-2018 master-1991 master-1995 master-2007 master-2009 master-2013 master-2017 rob@vps:mast$ rm master-[2000-2019]* rob@vps:mast$ ls empty directory`
                      – Robert Zabkiewicz
                      1 hour ago







                    • 1




                      none of your commands will remove a file with the name master-of-puppets
                      – mosvy
                      1 hour ago














                    up vote
                    0
                    down vote













                    If all files you want to delete has pattern like master-YYYY*, you can use those patterns:



                    rm -rf master-???[0-79]*
                    rm -rf master-??[02-9]*
                    rm -rf master-?[1-9]*
                    rm -rf master-[013-9]*


                    The goal is to ommit digits from a year number, so on first place after master- we need to ommit (don't remove) digit 2, on 2nd place digit 0, on 3rd place digit 1, and on 4th place - digit 8
                    I tried it just a minute before, and is enough to run only first two of them.



                    Second method:
                    You can move master-2018 to another dir, e.g. /tmp,
                    then remove everything with master-*, and move back your master-2018 from tmp.



                    mkdir /tmp/backup
                    mv -r master-2018* /tmp/backup
                    rm -rf master-*
                    mv -r /tmp/backup/* .





                    share|improve this answer










                    New contributor




                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.













                    • 1




                      Ahh so, rm -rf master-????[2019-9999]* would remove all files from master-2019* to master-9999*?
                      – Dan James Palmer
                      1 hour ago










                    • No, it not works this way. You can not specify numbers in [ ] braces. Only digits. You specify which digits will be places in the place of [xxxxxxx]. So max possibilities is range from 0 to 9 like this [0-9] or this [0123456789]. This can replace only one character from file name. rob@vps:mast$ ls master-1990 master-1994 master-2006 master-2010 master-2014 master-2018 master-1991 master-1995 master-2007 master-2009 master-2013 master-2017 rob@vps:mast$ rm master-[2000-2019]* rob@vps:mast$ ls empty directory`
                      – Robert Zabkiewicz
                      1 hour ago







                    • 1




                      none of your commands will remove a file with the name master-of-puppets
                      – mosvy
                      1 hour ago












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    If all files you want to delete has pattern like master-YYYY*, you can use those patterns:



                    rm -rf master-???[0-79]*
                    rm -rf master-??[02-9]*
                    rm -rf master-?[1-9]*
                    rm -rf master-[013-9]*


                    The goal is to ommit digits from a year number, so on first place after master- we need to ommit (don't remove) digit 2, on 2nd place digit 0, on 3rd place digit 1, and on 4th place - digit 8
                    I tried it just a minute before, and is enough to run only first two of them.



                    Second method:
                    You can move master-2018 to another dir, e.g. /tmp,
                    then remove everything with master-*, and move back your master-2018 from tmp.



                    mkdir /tmp/backup
                    mv -r master-2018* /tmp/backup
                    rm -rf master-*
                    mv -r /tmp/backup/* .





                    share|improve this answer










                    New contributor




                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    If all files you want to delete has pattern like master-YYYY*, you can use those patterns:



                    rm -rf master-???[0-79]*
                    rm -rf master-??[02-9]*
                    rm -rf master-?[1-9]*
                    rm -rf master-[013-9]*


                    The goal is to ommit digits from a year number, so on first place after master- we need to ommit (don't remove) digit 2, on 2nd place digit 0, on 3rd place digit 1, and on 4th place - digit 8
                    I tried it just a minute before, and is enough to run only first two of them.



                    Second method:
                    You can move master-2018 to another dir, e.g. /tmp,
                    then remove everything with master-*, and move back your master-2018 from tmp.



                    mkdir /tmp/backup
                    mv -r master-2018* /tmp/backup
                    rm -rf master-*
                    mv -r /tmp/backup/* .






                    share|improve this answer










                    New contributor




                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    share|improve this answer



                    share|improve this answer








                    edited 1 hour ago





















                    New contributor




                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered 1 hour ago









                    Robert Zabkiewicz

                    11




                    11




                    New contributor




                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    Robert Zabkiewicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.







                    • 1




                      Ahh so, rm -rf master-????[2019-9999]* would remove all files from master-2019* to master-9999*?
                      – Dan James Palmer
                      1 hour ago










                    • No, it not works this way. You can not specify numbers in [ ] braces. Only digits. You specify which digits will be places in the place of [xxxxxxx]. So max possibilities is range from 0 to 9 like this [0-9] or this [0123456789]. This can replace only one character from file name. rob@vps:mast$ ls master-1990 master-1994 master-2006 master-2010 master-2014 master-2018 master-1991 master-1995 master-2007 master-2009 master-2013 master-2017 rob@vps:mast$ rm master-[2000-2019]* rob@vps:mast$ ls empty directory`
                      – Robert Zabkiewicz
                      1 hour ago







                    • 1




                      none of your commands will remove a file with the name master-of-puppets
                      – mosvy
                      1 hour ago












                    • 1




                      Ahh so, rm -rf master-????[2019-9999]* would remove all files from master-2019* to master-9999*?
                      – Dan James Palmer
                      1 hour ago










                    • No, it not works this way. You can not specify numbers in [ ] braces. Only digits. You specify which digits will be places in the place of [xxxxxxx]. So max possibilities is range from 0 to 9 like this [0-9] or this [0123456789]. This can replace only one character from file name. rob@vps:mast$ ls master-1990 master-1994 master-2006 master-2010 master-2014 master-2018 master-1991 master-1995 master-2007 master-2009 master-2013 master-2017 rob@vps:mast$ rm master-[2000-2019]* rob@vps:mast$ ls empty directory`
                      – Robert Zabkiewicz
                      1 hour ago







                    • 1




                      none of your commands will remove a file with the name master-of-puppets
                      – mosvy
                      1 hour ago







                    1




                    1




                    Ahh so, rm -rf master-????[2019-9999]* would remove all files from master-2019* to master-9999*?
                    – Dan James Palmer
                    1 hour ago




                    Ahh so, rm -rf master-????[2019-9999]* would remove all files from master-2019* to master-9999*?
                    – Dan James Palmer
                    1 hour ago












                    No, it not works this way. You can not specify numbers in [ ] braces. Only digits. You specify which digits will be places in the place of [xxxxxxx]. So max possibilities is range from 0 to 9 like this [0-9] or this [0123456789]. This can replace only one character from file name. rob@vps:mast$ ls master-1990 master-1994 master-2006 master-2010 master-2014 master-2018 master-1991 master-1995 master-2007 master-2009 master-2013 master-2017 rob@vps:mast$ rm master-[2000-2019]* rob@vps:mast$ ls empty directory`
                    – Robert Zabkiewicz
                    1 hour ago





                    No, it not works this way. You can not specify numbers in [ ] braces. Only digits. You specify which digits will be places in the place of [xxxxxxx]. So max possibilities is range from 0 to 9 like this [0-9] or this [0123456789]. This can replace only one character from file name. rob@vps:mast$ ls master-1990 master-1994 master-2006 master-2010 master-2014 master-2018 master-1991 master-1995 master-2007 master-2009 master-2013 master-2017 rob@vps:mast$ rm master-[2000-2019]* rob@vps:mast$ ls empty directory`
                    – Robert Zabkiewicz
                    1 hour ago





                    1




                    1




                    none of your commands will remove a file with the name master-of-puppets
                    – mosvy
                    1 hour ago




                    none of your commands will remove a file with the name master-of-puppets
                    – mosvy
                    1 hour ago










                    Dan James Palmer is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    Dan James Palmer is a new contributor. Be nice, and check out our Code of Conduct.












                    Dan James Palmer is a new contributor. Be nice, and check out our Code of Conduct.











                    Dan James Palmer is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480241%2fremove-files-that-start-with-but-dont-contain%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery