How do I match only dotfiles in bash?

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











up vote
3
down vote

favorite
1












rm -rf .* will only not end horribly because rm refuses to delete . and ...



How do I exclude these special directories from a glob pattern?



This is not solved by dotglob since I want to match only files beginning with a dot not all files.










share|improve this question



















  • 1




    History: unix.stackexchange.com/a/90075/117549
    – Jeff Schaller
    21 mins ago










  • Possible duplicate of grep ignores files starting with dot
    – Jeff Schaller
    18 mins ago










  • @JeffSchaller, doesn't that one ask for all files, which is easily accomplished with dotglob? Here, they just want those starting with a dot.
    – ilkkachu
    13 mins ago










  • Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
    – Jeff Schaller
    9 mins ago














up vote
3
down vote

favorite
1












rm -rf .* will only not end horribly because rm refuses to delete . and ...



How do I exclude these special directories from a glob pattern?



This is not solved by dotglob since I want to match only files beginning with a dot not all files.










share|improve this question



















  • 1




    History: unix.stackexchange.com/a/90075/117549
    – Jeff Schaller
    21 mins ago










  • Possible duplicate of grep ignores files starting with dot
    – Jeff Schaller
    18 mins ago










  • @JeffSchaller, doesn't that one ask for all files, which is easily accomplished with dotglob? Here, they just want those starting with a dot.
    – ilkkachu
    13 mins ago










  • Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
    – Jeff Schaller
    9 mins ago












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





rm -rf .* will only not end horribly because rm refuses to delete . and ...



How do I exclude these special directories from a glob pattern?



This is not solved by dotglob since I want to match only files beginning with a dot not all files.










share|improve this question















rm -rf .* will only not end horribly because rm refuses to delete . and ...



How do I exclude these special directories from a glob pattern?



This is not solved by dotglob since I want to match only files beginning with a dot not all files.







bash wildcards dot-files






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 24 mins ago









Ipor Sircer

9,5791920




9,5791920










asked 28 mins ago









Franklin

1233




1233







  • 1




    History: unix.stackexchange.com/a/90075/117549
    – Jeff Schaller
    21 mins ago










  • Possible duplicate of grep ignores files starting with dot
    – Jeff Schaller
    18 mins ago










  • @JeffSchaller, doesn't that one ask for all files, which is easily accomplished with dotglob? Here, they just want those starting with a dot.
    – ilkkachu
    13 mins ago










  • Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
    – Jeff Schaller
    9 mins ago












  • 1




    History: unix.stackexchange.com/a/90075/117549
    – Jeff Schaller
    21 mins ago










  • Possible duplicate of grep ignores files starting with dot
    – Jeff Schaller
    18 mins ago










  • @JeffSchaller, doesn't that one ask for all files, which is easily accomplished with dotglob? Here, they just want those starting with a dot.
    – ilkkachu
    13 mins ago










  • Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
    – Jeff Schaller
    9 mins ago







1




1




History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago




History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago












Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago




Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago












@JeffSchaller, doesn't that one ask for all files, which is easily accomplished with dotglob? Here, they just want those starting with a dot.
– ilkkachu
13 mins ago




@JeffSchaller, doesn't that one ask for all files, which is easily accomplished with dotglob? Here, they just want those starting with a dot.
– ilkkachu
13 mins ago












Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago




Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago










4 Answers
4






active

oldest

votes

















up vote
4
down vote













This should do it:



rm -rf .[^.] .??* 


This command can catch all cases.



.[^.] will catch any two character entries.
.??* will only match 3+ character filenames.






share|improve this answer



























    up vote
    0
    down vote













    You need to exclude single and double dots:



    rm -rf ..?,.[!.]*



    • ..?* matches everything with two dots followed by anything


    • .[!.]* matches everything with single dot not followed by another dot





    share|improve this answer



























      up vote
      0
      down vote













      With extglob:



      $ shopt -s extglob
      $ touch ... .a .bbb ..c foo
      $ echo .!(.|)
      ... .a .bbb ..c


      !(.|) matches anything but a dot or empty, so .!(.|) matches anything starting with a dot, except . and ...






      share|improve this answer



























        up vote
        0
        down vote













        @Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead



        ls .??*


        It's absolutely true that this will miss files like .a, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.





        share




















          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%2f476245%2fhow-do-i-match-only-dotfiles-in-bash%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
          4
          down vote













          This should do it:



          rm -rf .[^.] .??* 


          This command can catch all cases.



          .[^.] will catch any two character entries.
          .??* will only match 3+ character filenames.






          share|improve this answer
























            up vote
            4
            down vote













            This should do it:



            rm -rf .[^.] .??* 


            This command can catch all cases.



            .[^.] will catch any two character entries.
            .??* will only match 3+ character filenames.






            share|improve this answer






















              up vote
              4
              down vote










              up vote
              4
              down vote









              This should do it:



              rm -rf .[^.] .??* 


              This command can catch all cases.



              .[^.] will catch any two character entries.
              .??* will only match 3+ character filenames.






              share|improve this answer












              This should do it:



              rm -rf .[^.] .??* 


              This command can catch all cases.



              .[^.] will catch any two character entries.
              .??* will only match 3+ character filenames.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 23 mins ago









              Goro

              10.2k64993




              10.2k64993






















                  up vote
                  0
                  down vote













                  You need to exclude single and double dots:



                  rm -rf ..?,.[!.]*



                  • ..?* matches everything with two dots followed by anything


                  • .[!.]* matches everything with single dot not followed by another dot





                  share|improve this answer
























                    up vote
                    0
                    down vote













                    You need to exclude single and double dots:



                    rm -rf ..?,.[!.]*



                    • ..?* matches everything with two dots followed by anything


                    • .[!.]* matches everything with single dot not followed by another dot





                    share|improve this answer






















                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      You need to exclude single and double dots:



                      rm -rf ..?,.[!.]*



                      • ..?* matches everything with two dots followed by anything


                      • .[!.]* matches everything with single dot not followed by another dot





                      share|improve this answer












                      You need to exclude single and double dots:



                      rm -rf ..?,.[!.]*



                      • ..?* matches everything with two dots followed by anything


                      • .[!.]* matches everything with single dot not followed by another dot






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 22 mins ago









                      jimmij

                      29.6k867102




                      29.6k867102




















                          up vote
                          0
                          down vote













                          With extglob:



                          $ shopt -s extglob
                          $ touch ... .a .bbb ..c foo
                          $ echo .!(.|)
                          ... .a .bbb ..c


                          !(.|) matches anything but a dot or empty, so .!(.|) matches anything starting with a dot, except . and ...






                          share|improve this answer
























                            up vote
                            0
                            down vote













                            With extglob:



                            $ shopt -s extglob
                            $ touch ... .a .bbb ..c foo
                            $ echo .!(.|)
                            ... .a .bbb ..c


                            !(.|) matches anything but a dot or empty, so .!(.|) matches anything starting with a dot, except . and ...






                            share|improve this answer






















                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              With extglob:



                              $ shopt -s extglob
                              $ touch ... .a .bbb ..c foo
                              $ echo .!(.|)
                              ... .a .bbb ..c


                              !(.|) matches anything but a dot or empty, so .!(.|) matches anything starting with a dot, except . and ...






                              share|improve this answer












                              With extglob:



                              $ shopt -s extglob
                              $ touch ... .a .bbb ..c foo
                              $ echo .!(.|)
                              ... .a .bbb ..c


                              !(.|) matches anything but a dot or empty, so .!(.|) matches anything starting with a dot, except . and ...







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 18 mins ago









                              ilkkachu

                              52.9k680145




                              52.9k680145




















                                  up vote
                                  0
                                  down vote













                                  @Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead



                                  ls .??*


                                  It's absolutely true that this will miss files like .a, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.





                                  share
























                                    up vote
                                    0
                                    down vote













                                    @Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead



                                    ls .??*


                                    It's absolutely true that this will miss files like .a, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.





                                    share






















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      @Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead



                                      ls .??*


                                      It's absolutely true that this will miss files like .a, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.





                                      share












                                      @Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead



                                      ls .??*


                                      It's absolutely true that this will miss files like .a, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.






                                      share











                                      share


                                      share










                                      answered 2 mins ago









                                      Dale Hagglund

                                      31612




                                      31612



























                                           

                                          draft saved


                                          draft discarded















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476245%2fhow-do-i-match-only-dotfiles-in-bash%23new-answer', 'question_page');

                                          );

                                          Post as a guest













































































                                          Comments

                                          Popular posts from this blog

                                          What does second last employer means? [closed]

                                          List of Gilmore Girls characters

                                          One-line joke