Using find, how to classify like ls -F ? (directories with a trailing slash)












1














I use find to get a list of files, then I grep it to do a path matching :



$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py


I would like to do like in ls -F and append a / for each directory.



Alternatively, how do I get find to show all directories matching case insensitive arthur ?










share|improve this question






















  • Related: How to use wc and piping to find how many files and directories are in a certain directory?
    – Stéphane Chazelas
    Dec 19 '18 at 9:06
















1














I use find to get a list of files, then I grep it to do a path matching :



$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py


I would like to do like in ls -F and append a / for each directory.



Alternatively, how do I get find to show all directories matching case insensitive arthur ?










share|improve this question






















  • Related: How to use wc and piping to find how many files and directories are in a certain directory?
    – Stéphane Chazelas
    Dec 19 '18 at 9:06














1












1








1







I use find to get a list of files, then I grep it to do a path matching :



$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py


I would like to do like in ls -F and append a / for each directory.



Alternatively, how do I get find to show all directories matching case insensitive arthur ?










share|improve this question













I use find to get a list of files, then I grep it to do a path matching :



$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py


I would like to do like in ls -F and append a / for each directory.



Alternatively, how do I get find to show all directories matching case insensitive arthur ?







bash grep find






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 19 '18 at 8:27









Robert Vanden Eynde

155




155












  • Related: How to use wc and piping to find how many files and directories are in a certain directory?
    – Stéphane Chazelas
    Dec 19 '18 at 9:06


















  • Related: How to use wc and piping to find how many files and directories are in a certain directory?
    – Stéphane Chazelas
    Dec 19 '18 at 9:06
















Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06




Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06










2 Answers
2






active

oldest

votes


















3














You can use disjunctions in find expressions to implement conditional processing; with GNU find:



find pc* -type d -printf "%p/n" -o -print


will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.



The way this works is as follows:





  • pc* specifies the paths to start from;


  • -type d matches directories;


  • -printf "%p/n" prints the path to the currently-processed file, followed by “/” and a newline; because it follows -type d, it is only executed if -type d matched (there’s an implicit conjunction);


  • -o introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is -type d -printf "%p/n" here, because conjunctions have higher precedence than disjunctions);


  • -print prints the path to the currently-processed file.


Showing all directories matching case-insensitive “arthur” can be done using other find expressions:



find . -type d -iname "*arthur*"





share|improve this answer























  • Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
    – Robert Vanden Eynde
    Dec 19 '18 at 8:53










  • You removerd the version find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print ), just curious about what the parenthesis and the ! meant ? :)
    – Robert Vanden Eynde
    Dec 22 '18 at 21:13






  • 1




    The parentheses group expressions, and ! negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print ) tells find to consider -type d -printf "%p/n" on the one hand, and ! -type d -print on the other; and ! -type d matches anything which isn’t a directory.
    – Stephen Kitt
    Dec 22 '18 at 21:25



















1














find has a huge amount of options and details. Another variant is to use printf with %y



$ find . -printf "%p:%yn"
./dir:d
./file:f


where %y adds a "d" or a "f" just like ls -l



$ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!' 





share|improve this answer





















    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',
    autoActivateHeartbeat: false,
    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489857%2fusing-find-how-to-classify-like-ls-f-directories-with-a-trailing-slash%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    You can use disjunctions in find expressions to implement conditional processing; with GNU find:



    find pc* -type d -printf "%p/n" -o -print


    will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.



    The way this works is as follows:





    • pc* specifies the paths to start from;


    • -type d matches directories;


    • -printf "%p/n" prints the path to the currently-processed file, followed by “/” and a newline; because it follows -type d, it is only executed if -type d matched (there’s an implicit conjunction);


    • -o introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is -type d -printf "%p/n" here, because conjunctions have higher precedence than disjunctions);


    • -print prints the path to the currently-processed file.


    Showing all directories matching case-insensitive “arthur” can be done using other find expressions:



    find . -type d -iname "*arthur*"





    share|improve this answer























    • Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
      – Robert Vanden Eynde
      Dec 19 '18 at 8:53










    • You removerd the version find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print ), just curious about what the parenthesis and the ! meant ? :)
      – Robert Vanden Eynde
      Dec 22 '18 at 21:13






    • 1




      The parentheses group expressions, and ! negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print ) tells find to consider -type d -printf "%p/n" on the one hand, and ! -type d -print on the other; and ! -type d matches anything which isn’t a directory.
      – Stephen Kitt
      Dec 22 '18 at 21:25
















    3














    You can use disjunctions in find expressions to implement conditional processing; with GNU find:



    find pc* -type d -printf "%p/n" -o -print


    will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.



    The way this works is as follows:





    • pc* specifies the paths to start from;


    • -type d matches directories;


    • -printf "%p/n" prints the path to the currently-processed file, followed by “/” and a newline; because it follows -type d, it is only executed if -type d matched (there’s an implicit conjunction);


    • -o introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is -type d -printf "%p/n" here, because conjunctions have higher precedence than disjunctions);


    • -print prints the path to the currently-processed file.


    Showing all directories matching case-insensitive “arthur” can be done using other find expressions:



    find . -type d -iname "*arthur*"





    share|improve this answer























    • Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
      – Robert Vanden Eynde
      Dec 19 '18 at 8:53










    • You removerd the version find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print ), just curious about what the parenthesis and the ! meant ? :)
      – Robert Vanden Eynde
      Dec 22 '18 at 21:13






    • 1




      The parentheses group expressions, and ! negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print ) tells find to consider -type d -printf "%p/n" on the one hand, and ! -type d -print on the other; and ! -type d matches anything which isn’t a directory.
      – Stephen Kitt
      Dec 22 '18 at 21:25














    3












    3








    3






    You can use disjunctions in find expressions to implement conditional processing; with GNU find:



    find pc* -type d -printf "%p/n" -o -print


    will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.



    The way this works is as follows:





    • pc* specifies the paths to start from;


    • -type d matches directories;


    • -printf "%p/n" prints the path to the currently-processed file, followed by “/” and a newline; because it follows -type d, it is only executed if -type d matched (there’s an implicit conjunction);


    • -o introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is -type d -printf "%p/n" here, because conjunctions have higher precedence than disjunctions);


    • -print prints the path to the currently-processed file.


    Showing all directories matching case-insensitive “arthur” can be done using other find expressions:



    find . -type d -iname "*arthur*"





    share|improve this answer














    You can use disjunctions in find expressions to implement conditional processing; with GNU find:



    find pc* -type d -printf "%p/n" -o -print


    will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.



    The way this works is as follows:





    • pc* specifies the paths to start from;


    • -type d matches directories;


    • -printf "%p/n" prints the path to the currently-processed file, followed by “/” and a newline; because it follows -type d, it is only executed if -type d matched (there’s an implicit conjunction);


    • -o introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is -type d -printf "%p/n" here, because conjunctions have higher precedence than disjunctions);


    • -print prints the path to the currently-processed file.


    Showing all directories matching case-insensitive “arthur” can be done using other find expressions:



    find . -type d -iname "*arthur*"






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 19 '18 at 9:03

























    answered Dec 19 '18 at 8:31









    Stephen Kitt

    164k24365444




    164k24365444












    • Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
      – Robert Vanden Eynde
      Dec 19 '18 at 8:53










    • You removerd the version find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print ), just curious about what the parenthesis and the ! meant ? :)
      – Robert Vanden Eynde
      Dec 22 '18 at 21:13






    • 1




      The parentheses group expressions, and ! negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print ) tells find to consider -type d -printf "%p/n" on the one hand, and ! -type d -print on the other; and ! -type d matches anything which isn’t a directory.
      – Stephen Kitt
      Dec 22 '18 at 21:25


















    • Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
      – Robert Vanden Eynde
      Dec 19 '18 at 8:53










    • You removerd the version find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print ), just curious about what the parenthesis and the ! meant ? :)
      – Robert Vanden Eynde
      Dec 22 '18 at 21:13






    • 1




      The parentheses group expressions, and ! negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print ) tells find to consider -type d -printf "%p/n" on the one hand, and ! -type d -print on the other; and ! -type d matches anything which isn’t a directory.
      – Stephen Kitt
      Dec 22 '18 at 21:25
















    Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
    – Robert Vanden Eynde
    Dec 19 '18 at 8:53




    Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
    – Robert Vanden Eynde
    Dec 19 '18 at 8:53












    You removerd the version find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print ), just curious about what the parenthesis and the ! meant ? :)
    – Robert Vanden Eynde
    Dec 22 '18 at 21:13




    You removerd the version find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print ), just curious about what the parenthesis and the ! meant ? :)
    – Robert Vanden Eynde
    Dec 22 '18 at 21:13




    1




    1




    The parentheses group expressions, and ! negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print ) tells find to consider -type d -printf "%p/n" on the one hand, and ! -type d -print on the other; and ! -type d matches anything which isn’t a directory.
    – Stephen Kitt
    Dec 22 '18 at 21:25




    The parentheses group expressions, and ! negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print ) tells find to consider -type d -printf "%p/n" on the one hand, and ! -type d -print on the other; and ! -type d matches anything which isn’t a directory.
    – Stephen Kitt
    Dec 22 '18 at 21:25













    1














    find has a huge amount of options and details. Another variant is to use printf with %y



    $ find . -printf "%p:%yn"
    ./dir:d
    ./file:f


    where %y adds a "d" or a "f" just like ls -l



    $ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!' 





    share|improve this answer


























      1














      find has a huge amount of options and details. Another variant is to use printf with %y



      $ find . -printf "%p:%yn"
      ./dir:d
      ./file:f


      where %y adds a "d" or a "f" just like ls -l



      $ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!' 





      share|improve this answer
























        1












        1








        1






        find has a huge amount of options and details. Another variant is to use printf with %y



        $ find . -printf "%p:%yn"
        ./dir:d
        ./file:f


        where %y adds a "d" or a "f" just like ls -l



        $ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!' 





        share|improve this answer












        find has a huge amount of options and details. Another variant is to use printf with %y



        $ find . -printf "%p:%yn"
        ./dir:d
        ./file:f


        where %y adds a "d" or a "f" just like ls -l



        $ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!' 






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 19 '18 at 9:05









        JJoao

        7,1041928




        7,1041928






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2funix.stackexchange.com%2fquestions%2f489857%2fusing-find-how-to-classify-like-ls-f-directories-with-a-trailing-slash%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

            Morgemoulin

            Scott Moir

            Souastre