Using regex for locate and grep to get only folders

Multi tool use
Multi tool use

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











up vote
0
down vote

favorite












When I try to search using locate and grep something like:



locate A-B | grep .dir


The result is:



.../A-B-C.dir
.../A-B-C.dir/file
.../A-B-C.dir/file1
.../A-B-D.dir
.../A-B-D.dir/file1
...


How to modify grep or locate to make the search finished with .dir and nothing more?



I have quite old system:




Secure Locate 2.7 - Released January 24, 2003



grep (GNU grep) 2.5.1








share|improve this question


























    up vote
    0
    down vote

    favorite












    When I try to search using locate and grep something like:



    locate A-B | grep .dir


    The result is:



    .../A-B-C.dir
    .../A-B-C.dir/file
    .../A-B-C.dir/file1
    .../A-B-D.dir
    .../A-B-D.dir/file1
    ...


    How to modify grep or locate to make the search finished with .dir and nothing more?



    I have quite old system:




    Secure Locate 2.7 - Released January 24, 2003



    grep (GNU grep) 2.5.1








    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      When I try to search using locate and grep something like:



      locate A-B | grep .dir


      The result is:



      .../A-B-C.dir
      .../A-B-C.dir/file
      .../A-B-C.dir/file1
      .../A-B-D.dir
      .../A-B-D.dir/file1
      ...


      How to modify grep or locate to make the search finished with .dir and nothing more?



      I have quite old system:




      Secure Locate 2.7 - Released January 24, 2003



      grep (GNU grep) 2.5.1








      share|improve this question














      When I try to search using locate and grep something like:



      locate A-B | grep .dir


      The result is:



      .../A-B-C.dir
      .../A-B-C.dir/file
      .../A-B-C.dir/file1
      .../A-B-D.dir
      .../A-B-D.dir/file1
      ...


      How to modify grep or locate to make the search finished with .dir and nothing more?



      I have quite old system:




      Secure Locate 2.7 - Released January 24, 2003



      grep (GNU grep) 2.5.1










      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 15:47

























      asked Mar 23 at 15:28









      XuMuK

      34




      34




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          If this is a Linux system, then chances are that you locate supports regular expressions:



          locate --regex 'A-B.*.dir$'


          If not,



          locate 'A-B' | grep '.dir$'


          The main point is to anchor the regular expression to the end of the line properly with $.



          Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir.






          share|improve this answer




















          • The second option is working. The first results empty line.
            – XuMuK
            Mar 23 at 15:38










          • @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system).
            – Kusalananda
            Mar 23 at 15:40










          • according to man locate it should work with regex.
            – XuMuK
            Mar 23 at 15:47










          • It's easier with the default wildcards anyway: locate '*A-B*.dir'
            – Stéphane Chazelas
            Mar 23 at 16:32










          • @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it.
            – XuMuK
            Mar 23 at 18:32










          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%2f433092%2fusing-regex-for-locate-and-grep-to-get-only-folders%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          If this is a Linux system, then chances are that you locate supports regular expressions:



          locate --regex 'A-B.*.dir$'


          If not,



          locate 'A-B' | grep '.dir$'


          The main point is to anchor the regular expression to the end of the line properly with $.



          Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir.






          share|improve this answer




















          • The second option is working. The first results empty line.
            – XuMuK
            Mar 23 at 15:38










          • @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system).
            – Kusalananda
            Mar 23 at 15:40










          • according to man locate it should work with regex.
            – XuMuK
            Mar 23 at 15:47










          • It's easier with the default wildcards anyway: locate '*A-B*.dir'
            – Stéphane Chazelas
            Mar 23 at 16:32










          • @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it.
            – XuMuK
            Mar 23 at 18:32














          up vote
          1
          down vote



          accepted










          If this is a Linux system, then chances are that you locate supports regular expressions:



          locate --regex 'A-B.*.dir$'


          If not,



          locate 'A-B' | grep '.dir$'


          The main point is to anchor the regular expression to the end of the line properly with $.



          Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir.






          share|improve this answer




















          • The second option is working. The first results empty line.
            – XuMuK
            Mar 23 at 15:38










          • @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system).
            – Kusalananda
            Mar 23 at 15:40










          • according to man locate it should work with regex.
            – XuMuK
            Mar 23 at 15:47










          • It's easier with the default wildcards anyway: locate '*A-B*.dir'
            – Stéphane Chazelas
            Mar 23 at 16:32










          • @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it.
            – XuMuK
            Mar 23 at 18:32












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          If this is a Linux system, then chances are that you locate supports regular expressions:



          locate --regex 'A-B.*.dir$'


          If not,



          locate 'A-B' | grep '.dir$'


          The main point is to anchor the regular expression to the end of the line properly with $.



          Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir.






          share|improve this answer












          If this is a Linux system, then chances are that you locate supports regular expressions:



          locate --regex 'A-B.*.dir$'


          If not,



          locate 'A-B' | grep '.dir$'


          The main point is to anchor the regular expression to the end of the line properly with $.



          Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 15:32









          Kusalananda

          102k13201317




          102k13201317











          • The second option is working. The first results empty line.
            – XuMuK
            Mar 23 at 15:38










          • @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system).
            – Kusalananda
            Mar 23 at 15:40










          • according to man locate it should work with regex.
            – XuMuK
            Mar 23 at 15:47










          • It's easier with the default wildcards anyway: locate '*A-B*.dir'
            – Stéphane Chazelas
            Mar 23 at 16:32










          • @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it.
            – XuMuK
            Mar 23 at 18:32
















          • The second option is working. The first results empty line.
            – XuMuK
            Mar 23 at 15:38










          • @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system).
            – Kusalananda
            Mar 23 at 15:40










          • according to man locate it should work with regex.
            – XuMuK
            Mar 23 at 15:47










          • It's easier with the default wildcards anyway: locate '*A-B*.dir'
            – Stéphane Chazelas
            Mar 23 at 16:32










          • @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it.
            – XuMuK
            Mar 23 at 18:32















          The second option is working. The first results empty line.
          – XuMuK
          Mar 23 at 15:38




          The second option is working. The first results empty line.
          – XuMuK
          Mar 23 at 15:38












          @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system).
          – Kusalananda
          Mar 23 at 15:40




          @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system).
          – Kusalananda
          Mar 23 at 15:40












          according to man locate it should work with regex.
          – XuMuK
          Mar 23 at 15:47




          according to man locate it should work with regex.
          – XuMuK
          Mar 23 at 15:47












          It's easier with the default wildcards anyway: locate '*A-B*.dir'
          – Stéphane Chazelas
          Mar 23 at 16:32




          It's easier with the default wildcards anyway: locate '*A-B*.dir'
          – Stéphane Chazelas
          Mar 23 at 16:32












          @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it.
          – XuMuK
          Mar 23 at 18:32




          @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it.
          – XuMuK
          Mar 23 at 18:32












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433092%2fusing-regex-for-locate-and-grep-to-get-only-folders%23new-answer', 'question_page');

          );

          Post as a guest













































































          vXR6svovmru y5,qRPCyGMWmc,CMorKa hYC mmhxyXQqs NKoXUvk
          vqJSlt,MfgEqSfaV5AvYtWkgp9UTii6q,x1z6q4yl 2c8 zKUBC F5W xSH7p85aCttHV3PS7sZUensj1vPgunvg

          Popular posts from this blog

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

          How many registers does an x86_64 CPU actually have?

          Displaying single band from multi-band raster using QGIS