Go through all folders whose names contain a given pattern [duplicate]

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








up vote
0
down vote

favorite













This question already has an answer here:



  • File list command line (hidden and subfolders)

    2 answers



let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .



stat -c %y "$1"


this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name







share|improve this question











marked as duplicate by αғsнιη, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • ll -lt | grep af you can try this
    – neferpitou
    Jun 6 at 13:58










  • You can run for loop. Something, like, for i in ls af*; do stat -c %y; done
    – Josef Klimuk
    Jun 6 at 14:16














up vote
0
down vote

favorite













This question already has an answer here:



  • File list command line (hidden and subfolders)

    2 answers



let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .



stat -c %y "$1"


this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name







share|improve this question











marked as duplicate by αғsнιη, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • ll -lt | grep af you can try this
    – neferpitou
    Jun 6 at 13:58










  • You can run for loop. Something, like, for i in ls af*; do stat -c %y; done
    – Josef Klimuk
    Jun 6 at 14:16












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • File list command line (hidden and subfolders)

    2 answers



let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .



stat -c %y "$1"


this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name







share|improve this question












This question already has an answer here:



  • File list command line (hidden and subfolders)

    2 answers



let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .



stat -c %y "$1"


this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name





This question already has an answer here:



  • File list command line (hidden and subfolders)

    2 answers









share|improve this question










share|improve this question




share|improve this question









asked Jun 6 at 13:51









Muh

253




253




marked as duplicate by αғsнιη, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by αғsнιη, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • ll -lt | grep af you can try this
    – neferpitou
    Jun 6 at 13:58










  • You can run for loop. Something, like, for i in ls af*; do stat -c %y; done
    – Josef Klimuk
    Jun 6 at 14:16
















  • ll -lt | grep af you can try this
    – neferpitou
    Jun 6 at 13:58










  • You can run for loop. Something, like, for i in ls af*; do stat -c %y; done
    – Josef Klimuk
    Jun 6 at 14:16















ll -lt | grep af you can try this
– neferpitou
Jun 6 at 13:58




ll -lt | grep af you can try this
– neferpitou
Jun 6 at 13:58












You can run for loop. Something, like, for i in ls af*; do stat -c %y; done
– Josef Klimuk
Jun 6 at 14:16




You can run for loop. Something, like, for i in ls af*; do stat -c %y; done
– Josef Klimuk
Jun 6 at 14:16










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










You can use find to search recursively in search_folder/ for directories (-type d) matching a specific pattern glob (e.g. -name 'af*'):





find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;


This will then execute (-exec ... ;) the command stat -c '%y %n' '' on each of the search results, replacing with the result path, starting with the given search_folder/.



Note that I modified your stat output to include the file name/path %n in the result, because otherwise you wouldn't see what file each modification date belongs to.






share|improve this answer





















  • yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
    – Muh
    Jun 6 at 14:21






  • 1




    You have to replace search_folder/ with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat command on all matching folders below it.
    – Byte Commander
    Jun 6 at 14:32






  • 1




    More efficient with: -exec … +
    – dessert
    Jun 6 at 16:31

















up vote
1
down vote













You can use shell globbing as follows:



stat -c %y af*/


af*/ matches every directory in the current directory beginning with “af”.

If this throws an error like



bash: /usr/bin/stat: Argument list too long


use this printf approach instead:



printf '%s' af*/ | xargs -0 stat -c %y


Example run



You might want to add %n to stat’s output…



$ ls
af af32 af42 bf cg45
$ stat -c %y af*/
2018-06-05 18:59:55.355277977 +0200
2018-06-04 19:01:28.968869600 +0200
2018-06-06 18:58:15.968639269 +0200
$ stat -c '%y %n' af*/
2018-06-05 18:59:55.355277977 +0200 af/
2018-06-04 19:01:28.968869600 +0200 af32/
2018-06-06 18:58:15.968639269 +0200 af42/





share|improve this answer






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    You can use find to search recursively in search_folder/ for directories (-type d) matching a specific pattern glob (e.g. -name 'af*'):





    find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;


    This will then execute (-exec ... ;) the command stat -c '%y %n' '' on each of the search results, replacing with the result path, starting with the given search_folder/.



    Note that I modified your stat output to include the file name/path %n in the result, because otherwise you wouldn't see what file each modification date belongs to.






    share|improve this answer





















    • yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
      – Muh
      Jun 6 at 14:21






    • 1




      You have to replace search_folder/ with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat command on all matching folders below it.
      – Byte Commander
      Jun 6 at 14:32






    • 1




      More efficient with: -exec … +
      – dessert
      Jun 6 at 16:31














    up vote
    1
    down vote



    accepted










    You can use find to search recursively in search_folder/ for directories (-type d) matching a specific pattern glob (e.g. -name 'af*'):





    find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;


    This will then execute (-exec ... ;) the command stat -c '%y %n' '' on each of the search results, replacing with the result path, starting with the given search_folder/.



    Note that I modified your stat output to include the file name/path %n in the result, because otherwise you wouldn't see what file each modification date belongs to.






    share|improve this answer





















    • yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
      – Muh
      Jun 6 at 14:21






    • 1




      You have to replace search_folder/ with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat command on all matching folders below it.
      – Byte Commander
      Jun 6 at 14:32






    • 1




      More efficient with: -exec … +
      – dessert
      Jun 6 at 16:31












    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    You can use find to search recursively in search_folder/ for directories (-type d) matching a specific pattern glob (e.g. -name 'af*'):





    find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;


    This will then execute (-exec ... ;) the command stat -c '%y %n' '' on each of the search results, replacing with the result path, starting with the given search_folder/.



    Note that I modified your stat output to include the file name/path %n in the result, because otherwise you wouldn't see what file each modification date belongs to.






    share|improve this answer













    You can use find to search recursively in search_folder/ for directories (-type d) matching a specific pattern glob (e.g. -name 'af*'):





    find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;


    This will then execute (-exec ... ;) the command stat -c '%y %n' '' on each of the search results, replacing with the result path, starting with the given search_folder/.



    Note that I modified your stat output to include the file name/path %n in the result, because otherwise you wouldn't see what file each modification date belongs to.







    share|improve this answer













    share|improve this answer



    share|improve this answer











    answered Jun 6 at 13:59









    Byte Commander

    57.9k26155263




    57.9k26155263











    • yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
      – Muh
      Jun 6 at 14:21






    • 1




      You have to replace search_folder/ with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat command on all matching folders below it.
      – Byte Commander
      Jun 6 at 14:32






    • 1




      More efficient with: -exec … +
      – dessert
      Jun 6 at 16:31
















    • yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
      – Muh
      Jun 6 at 14:21






    • 1




      You have to replace search_folder/ with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat command on all matching folders below it.
      – Byte Commander
      Jun 6 at 14:32






    • 1




      More efficient with: -exec … +
      – dessert
      Jun 6 at 16:31















    yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
    – Muh
    Jun 6 at 14:21




    yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
    – Muh
    Jun 6 at 14:21




    1




    1




    You have to replace search_folder/ with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat command on all matching folders below it.
    – Byte Commander
    Jun 6 at 14:32




    You have to replace search_folder/ with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat command on all matching folders below it.
    – Byte Commander
    Jun 6 at 14:32




    1




    1




    More efficient with: -exec … +
    – dessert
    Jun 6 at 16:31




    More efficient with: -exec … +
    – dessert
    Jun 6 at 16:31












    up vote
    1
    down vote













    You can use shell globbing as follows:



    stat -c %y af*/


    af*/ matches every directory in the current directory beginning with “af”.

    If this throws an error like



    bash: /usr/bin/stat: Argument list too long


    use this printf approach instead:



    printf '%s' af*/ | xargs -0 stat -c %y


    Example run



    You might want to add %n to stat’s output…



    $ ls
    af af32 af42 bf cg45
    $ stat -c %y af*/
    2018-06-05 18:59:55.355277977 +0200
    2018-06-04 19:01:28.968869600 +0200
    2018-06-06 18:58:15.968639269 +0200
    $ stat -c '%y %n' af*/
    2018-06-05 18:59:55.355277977 +0200 af/
    2018-06-04 19:01:28.968869600 +0200 af32/
    2018-06-06 18:58:15.968639269 +0200 af42/





    share|improve this answer



























      up vote
      1
      down vote













      You can use shell globbing as follows:



      stat -c %y af*/


      af*/ matches every directory in the current directory beginning with “af”.

      If this throws an error like



      bash: /usr/bin/stat: Argument list too long


      use this printf approach instead:



      printf '%s' af*/ | xargs -0 stat -c %y


      Example run



      You might want to add %n to stat’s output…



      $ ls
      af af32 af42 bf cg45
      $ stat -c %y af*/
      2018-06-05 18:59:55.355277977 +0200
      2018-06-04 19:01:28.968869600 +0200
      2018-06-06 18:58:15.968639269 +0200
      $ stat -c '%y %n' af*/
      2018-06-05 18:59:55.355277977 +0200 af/
      2018-06-04 19:01:28.968869600 +0200 af32/
      2018-06-06 18:58:15.968639269 +0200 af42/





      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        You can use shell globbing as follows:



        stat -c %y af*/


        af*/ matches every directory in the current directory beginning with “af”.

        If this throws an error like



        bash: /usr/bin/stat: Argument list too long


        use this printf approach instead:



        printf '%s' af*/ | xargs -0 stat -c %y


        Example run



        You might want to add %n to stat’s output…



        $ ls
        af af32 af42 bf cg45
        $ stat -c %y af*/
        2018-06-05 18:59:55.355277977 +0200
        2018-06-04 19:01:28.968869600 +0200
        2018-06-06 18:58:15.968639269 +0200
        $ stat -c '%y %n' af*/
        2018-06-05 18:59:55.355277977 +0200 af/
        2018-06-04 19:01:28.968869600 +0200 af32/
        2018-06-06 18:58:15.968639269 +0200 af42/





        share|improve this answer















        You can use shell globbing as follows:



        stat -c %y af*/


        af*/ matches every directory in the current directory beginning with “af”.

        If this throws an error like



        bash: /usr/bin/stat: Argument list too long


        use this printf approach instead:



        printf '%s' af*/ | xargs -0 stat -c %y


        Example run



        You might want to add %n to stat’s output…



        $ ls
        af af32 af42 bf cg45
        $ stat -c %y af*/
        2018-06-05 18:59:55.355277977 +0200
        2018-06-04 19:01:28.968869600 +0200
        2018-06-06 18:58:15.968639269 +0200
        $ stat -c '%y %n' af*/
        2018-06-05 18:59:55.355277977 +0200 af/
        2018-06-04 19:01:28.968869600 +0200 af32/
        2018-06-06 18:58:15.968639269 +0200 af42/






        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jun 6 at 17:59


























        answered Jun 6 at 17:06









        dessert

        19.4k55494




        19.4k55494












            Popular posts from this blog

            pylint3 and pip3 broken

            Missing snmpget and snmpwalk

            How to enroll fingerprints to Ubuntu 17.10 with VFS491