find . * -exec ll ; -> with just one result instead of four

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











up vote
2
down vote

favorite












I'd like to use find command to search all files in one directory:



find . * -exec ll ;



Result shows four (!) results per file:



  • file123

  • ./test/file123

  • file123

  • test/file123

Is it possible to show just the second result ./test/file123 using find-out-of-the-box-command (so without using things like | grep '^./')?



I'm using latest version of HP/UX.










share|improve this question



















  • 2




    Where do you have this command from? just use find . - or just - ll. The difference is that find will find files recursively. Also note. Don't use ll in scripts! ll is just an alias (In Ubuntu it means ls -alFh). This is not portable in any ways.
    – RoVo
    Sep 10 at 9:10














up vote
2
down vote

favorite












I'd like to use find command to search all files in one directory:



find . * -exec ll ;



Result shows four (!) results per file:



  • file123

  • ./test/file123

  • file123

  • test/file123

Is it possible to show just the second result ./test/file123 using find-out-of-the-box-command (so without using things like | grep '^./')?



I'm using latest version of HP/UX.










share|improve this question



















  • 2




    Where do you have this command from? just use find . - or just - ll. The difference is that find will find files recursively. Also note. Don't use ll in scripts! ll is just an alias (In Ubuntu it means ls -alFh). This is not portable in any ways.
    – RoVo
    Sep 10 at 9:10












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'd like to use find command to search all files in one directory:



find . * -exec ll ;



Result shows four (!) results per file:



  • file123

  • ./test/file123

  • file123

  • test/file123

Is it possible to show just the second result ./test/file123 using find-out-of-the-box-command (so without using things like | grep '^./')?



I'm using latest version of HP/UX.










share|improve this question















I'd like to use find command to search all files in one directory:



find . * -exec ll ;



Result shows four (!) results per file:



  • file123

  • ./test/file123

  • file123

  • test/file123

Is it possible to show just the second result ./test/file123 using find-out-of-the-box-command (so without using things like | grep '^./')?



I'm using latest version of HP/UX.







find exec hp-ux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 10 at 12:28









Rui F Ribeiro

36.7k1271117




36.7k1271117










asked Sep 10 at 9:00









MyUserName

111




111







  • 2




    Where do you have this command from? just use find . - or just - ll. The difference is that find will find files recursively. Also note. Don't use ll in scripts! ll is just an alias (In Ubuntu it means ls -alFh). This is not portable in any ways.
    – RoVo
    Sep 10 at 9:10












  • 2




    Where do you have this command from? just use find . - or just - ll. The difference is that find will find files recursively. Also note. Don't use ll in scripts! ll is just an alias (In Ubuntu it means ls -alFh). This is not portable in any ways.
    – RoVo
    Sep 10 at 9:10







2




2




Where do you have this command from? just use find . - or just - ll. The difference is that find will find files recursively. Also note. Don't use ll in scripts! ll is just an alias (In Ubuntu it means ls -alFh). This is not portable in any ways.
– RoVo
Sep 10 at 9:10




Where do you have this command from? just use find . - or just - ll. The difference is that find will find files recursively. Also note. Don't use ll in scripts! ll is just an alias (In Ubuntu it means ls -alFh). This is not portable in any ways.
– RoVo
Sep 10 at 9:10










3 Answers
3






active

oldest

votes

















up vote
5
down vote













find . * -exec ll ;


Passes ., and the list of non-hidden files in the current directory (expanded from * by the shell), including the test subdirectory (and if any of those files started with - or if there was a file called ! or (, )... that would cause find to report a syntax error).



So you're telling find to look for files recursively in ., but also in test. So find will find test twice and also test/file123 twice.



ll which I suppose is a script that does ls -l is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d option).



So ll will be called with ./test and test as arguments in which cases if will list the details of the files in its content (including test/file).



And it will be called with ./test/file123 and test/file123.



Here, you'd want:



find . -exec ls -ld +


(using + means that more than one file will be passed as arguments to ls which is more efficient and also lets ls sort that list of files).



Your find may even support a -ls predicate which behaves a bit list ls -lsid:



find . -ls





share|improve this answer




















  • I never use find . myself because this is redundant. find will always search in the current directory if the directory is unspecified.
    – Fox
    Sep 10 at 13:48






  • 2




    @Fox, that's a GNU extension. Many find implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find specification does as well.
    – Stéphane Chazelas
    Sep 10 at 13:54











  • Thank you! I learned something. :)
    – Fox
    Sep 10 at 14:07

















up vote
5
down vote













You are getting four lines of output because you you ask find to search the current directory (.) as well as everything that * expands to.



For the current directory, find will proceed to invoke ll on the things that it finds, which will be the current directory, the test directory and the file in the test directory. This lists file123 twice.



It will then search everything that * expands to, which will be the test directory. Now it will use ll on test again and on the file within. This lists your file twice again.



Instead, if you're looking for a regular file, use -type f. And you don't have to use ll (or ls) to get the results from find as it will list the found pathnames by default. Also, just give find the current directory (or test) as the search path:



find . -type f


If you know that you are looking for a file with the exact name file123:



find . -type f -name 'file123'


If you want ls -l-like output rather than a pathname:



find . -type f -name 'file123' -ls





share|improve this answer






















  • If you want to limit the results to files within those top-level directories, like "test", you might consider using the -maxdepth and -mindepth option as well. In this case: -mindepth 2 and -maxdepth 2.
    – Todd Walton
    Sep 10 at 15:32










  • @ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better -depth 2 with NetBSD find. See delete folders older than 1 day for instance for a POSIX equivalent
    – Stéphane Chazelas
    Sep 10 at 18:00

















up vote
0
down vote













Please note that find will search recursively in all the directories.

Find will return not only files, but also directories!



If you want to list all files within the test directory, all you need is the following command:
find test/ -type f



Also, I don't know what you are trying to achieve, but check your find manpage... You are using -exec ll ; and I suspect there's probably a find option that will do what you need (filter files by size, modification date, etc.)






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',
    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%2f467988%2ffind-exec-ll-with-just-one-result-instead-of-four%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    find . * -exec ll ;


    Passes ., and the list of non-hidden files in the current directory (expanded from * by the shell), including the test subdirectory (and if any of those files started with - or if there was a file called ! or (, )... that would cause find to report a syntax error).



    So you're telling find to look for files recursively in ., but also in test. So find will find test twice and also test/file123 twice.



    ll which I suppose is a script that does ls -l is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d option).



    So ll will be called with ./test and test as arguments in which cases if will list the details of the files in its content (including test/file).



    And it will be called with ./test/file123 and test/file123.



    Here, you'd want:



    find . -exec ls -ld +


    (using + means that more than one file will be passed as arguments to ls which is more efficient and also lets ls sort that list of files).



    Your find may even support a -ls predicate which behaves a bit list ls -lsid:



    find . -ls





    share|improve this answer




















    • I never use find . myself because this is redundant. find will always search in the current directory if the directory is unspecified.
      – Fox
      Sep 10 at 13:48






    • 2




      @Fox, that's a GNU extension. Many find implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find specification does as well.
      – Stéphane Chazelas
      Sep 10 at 13:54











    • Thank you! I learned something. :)
      – Fox
      Sep 10 at 14:07














    up vote
    5
    down vote













    find . * -exec ll ;


    Passes ., and the list of non-hidden files in the current directory (expanded from * by the shell), including the test subdirectory (and if any of those files started with - or if there was a file called ! or (, )... that would cause find to report a syntax error).



    So you're telling find to look for files recursively in ., but also in test. So find will find test twice and also test/file123 twice.



    ll which I suppose is a script that does ls -l is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d option).



    So ll will be called with ./test and test as arguments in which cases if will list the details of the files in its content (including test/file).



    And it will be called with ./test/file123 and test/file123.



    Here, you'd want:



    find . -exec ls -ld +


    (using + means that more than one file will be passed as arguments to ls which is more efficient and also lets ls sort that list of files).



    Your find may even support a -ls predicate which behaves a bit list ls -lsid:



    find . -ls





    share|improve this answer




















    • I never use find . myself because this is redundant. find will always search in the current directory if the directory is unspecified.
      – Fox
      Sep 10 at 13:48






    • 2




      @Fox, that's a GNU extension. Many find implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find specification does as well.
      – Stéphane Chazelas
      Sep 10 at 13:54











    • Thank you! I learned something. :)
      – Fox
      Sep 10 at 14:07












    up vote
    5
    down vote










    up vote
    5
    down vote









    find . * -exec ll ;


    Passes ., and the list of non-hidden files in the current directory (expanded from * by the shell), including the test subdirectory (and if any of those files started with - or if there was a file called ! or (, )... that would cause find to report a syntax error).



    So you're telling find to look for files recursively in ., but also in test. So find will find test twice and also test/file123 twice.



    ll which I suppose is a script that does ls -l is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d option).



    So ll will be called with ./test and test as arguments in which cases if will list the details of the files in its content (including test/file).



    And it will be called with ./test/file123 and test/file123.



    Here, you'd want:



    find . -exec ls -ld +


    (using + means that more than one file will be passed as arguments to ls which is more efficient and also lets ls sort that list of files).



    Your find may even support a -ls predicate which behaves a bit list ls -lsid:



    find . -ls





    share|improve this answer












    find . * -exec ll ;


    Passes ., and the list of non-hidden files in the current directory (expanded from * by the shell), including the test subdirectory (and if any of those files started with - or if there was a file called ! or (, )... that would cause find to report a syntax error).



    So you're telling find to look for files recursively in ., but also in test. So find will find test twice and also test/file123 twice.



    ll which I suppose is a script that does ls -l is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d option).



    So ll will be called with ./test and test as arguments in which cases if will list the details of the files in its content (including test/file).



    And it will be called with ./test/file123 and test/file123.



    Here, you'd want:



    find . -exec ls -ld +


    (using + means that more than one file will be passed as arguments to ls which is more efficient and also lets ls sort that list of files).



    Your find may even support a -ls predicate which behaves a bit list ls -lsid:



    find . -ls






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 10 at 9:13









    Stéphane Chazelas

    285k53525864




    285k53525864











    • I never use find . myself because this is redundant. find will always search in the current directory if the directory is unspecified.
      – Fox
      Sep 10 at 13:48






    • 2




      @Fox, that's a GNU extension. Many find implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find specification does as well.
      – Stéphane Chazelas
      Sep 10 at 13:54











    • Thank you! I learned something. :)
      – Fox
      Sep 10 at 14:07
















    • I never use find . myself because this is redundant. find will always search in the current directory if the directory is unspecified.
      – Fox
      Sep 10 at 13:48






    • 2




      @Fox, that's a GNU extension. Many find implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find specification does as well.
      – Stéphane Chazelas
      Sep 10 at 13:54











    • Thank you! I learned something. :)
      – Fox
      Sep 10 at 14:07















    I never use find . myself because this is redundant. find will always search in the current directory if the directory is unspecified.
    – Fox
    Sep 10 at 13:48




    I never use find . myself because this is redundant. find will always search in the current directory if the directory is unspecified.
    – Fox
    Sep 10 at 13:48




    2




    2




    @Fox, that's a GNU extension. Many find implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find specification does as well.
    – Stéphane Chazelas
    Sep 10 at 13:54





    @Fox, that's a GNU extension. Many find implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find specification does as well.
    – Stéphane Chazelas
    Sep 10 at 13:54













    Thank you! I learned something. :)
    – Fox
    Sep 10 at 14:07




    Thank you! I learned something. :)
    – Fox
    Sep 10 at 14:07












    up vote
    5
    down vote













    You are getting four lines of output because you you ask find to search the current directory (.) as well as everything that * expands to.



    For the current directory, find will proceed to invoke ll on the things that it finds, which will be the current directory, the test directory and the file in the test directory. This lists file123 twice.



    It will then search everything that * expands to, which will be the test directory. Now it will use ll on test again and on the file within. This lists your file twice again.



    Instead, if you're looking for a regular file, use -type f. And you don't have to use ll (or ls) to get the results from find as it will list the found pathnames by default. Also, just give find the current directory (or test) as the search path:



    find . -type f


    If you know that you are looking for a file with the exact name file123:



    find . -type f -name 'file123'


    If you want ls -l-like output rather than a pathname:



    find . -type f -name 'file123' -ls





    share|improve this answer






















    • If you want to limit the results to files within those top-level directories, like "test", you might consider using the -maxdepth and -mindepth option as well. In this case: -mindepth 2 and -maxdepth 2.
      – Todd Walton
      Sep 10 at 15:32










    • @ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better -depth 2 with NetBSD find. See delete folders older than 1 day for instance for a POSIX equivalent
      – Stéphane Chazelas
      Sep 10 at 18:00














    up vote
    5
    down vote













    You are getting four lines of output because you you ask find to search the current directory (.) as well as everything that * expands to.



    For the current directory, find will proceed to invoke ll on the things that it finds, which will be the current directory, the test directory and the file in the test directory. This lists file123 twice.



    It will then search everything that * expands to, which will be the test directory. Now it will use ll on test again and on the file within. This lists your file twice again.



    Instead, if you're looking for a regular file, use -type f. And you don't have to use ll (or ls) to get the results from find as it will list the found pathnames by default. Also, just give find the current directory (or test) as the search path:



    find . -type f


    If you know that you are looking for a file with the exact name file123:



    find . -type f -name 'file123'


    If you want ls -l-like output rather than a pathname:



    find . -type f -name 'file123' -ls





    share|improve this answer






















    • If you want to limit the results to files within those top-level directories, like "test", you might consider using the -maxdepth and -mindepth option as well. In this case: -mindepth 2 and -maxdepth 2.
      – Todd Walton
      Sep 10 at 15:32










    • @ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better -depth 2 with NetBSD find. See delete folders older than 1 day for instance for a POSIX equivalent
      – Stéphane Chazelas
      Sep 10 at 18:00












    up vote
    5
    down vote










    up vote
    5
    down vote









    You are getting four lines of output because you you ask find to search the current directory (.) as well as everything that * expands to.



    For the current directory, find will proceed to invoke ll on the things that it finds, which will be the current directory, the test directory and the file in the test directory. This lists file123 twice.



    It will then search everything that * expands to, which will be the test directory. Now it will use ll on test again and on the file within. This lists your file twice again.



    Instead, if you're looking for a regular file, use -type f. And you don't have to use ll (or ls) to get the results from find as it will list the found pathnames by default. Also, just give find the current directory (or test) as the search path:



    find . -type f


    If you know that you are looking for a file with the exact name file123:



    find . -type f -name 'file123'


    If you want ls -l-like output rather than a pathname:



    find . -type f -name 'file123' -ls





    share|improve this answer














    You are getting four lines of output because you you ask find to search the current directory (.) as well as everything that * expands to.



    For the current directory, find will proceed to invoke ll on the things that it finds, which will be the current directory, the test directory and the file in the test directory. This lists file123 twice.



    It will then search everything that * expands to, which will be the test directory. Now it will use ll on test again and on the file within. This lists your file twice again.



    Instead, if you're looking for a regular file, use -type f. And you don't have to use ll (or ls) to get the results from find as it will list the found pathnames by default. Also, just give find the current directory (or test) as the search path:



    find . -type f


    If you know that you are looking for a file with the exact name file123:



    find . -type f -name 'file123'


    If you want ls -l-like output rather than a pathname:



    find . -type f -name 'file123' -ls






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 10 at 11:46

























    answered Sep 10 at 9:10









    Kusalananda

    107k14209329




    107k14209329











    • If you want to limit the results to files within those top-level directories, like "test", you might consider using the -maxdepth and -mindepth option as well. In this case: -mindepth 2 and -maxdepth 2.
      – Todd Walton
      Sep 10 at 15:32










    • @ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better -depth 2 with NetBSD find. See delete folders older than 1 day for instance for a POSIX equivalent
      – Stéphane Chazelas
      Sep 10 at 18:00
















    • If you want to limit the results to files within those top-level directories, like "test", you might consider using the -maxdepth and -mindepth option as well. In this case: -mindepth 2 and -maxdepth 2.
      – Todd Walton
      Sep 10 at 15:32










    • @ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better -depth 2 with NetBSD find. See delete folders older than 1 day for instance for a POSIX equivalent
      – Stéphane Chazelas
      Sep 10 at 18:00















    If you want to limit the results to files within those top-level directories, like "test", you might consider using the -maxdepth and -mindepth option as well. In this case: -mindepth 2 and -maxdepth 2.
    – Todd Walton
    Sep 10 at 15:32




    If you want to limit the results to files within those top-level directories, like "test", you might consider using the -maxdepth and -mindepth option as well. In this case: -mindepth 2 and -maxdepth 2.
    – Todd Walton
    Sep 10 at 15:32












    @ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better -depth 2 with NetBSD find. See delete folders older than 1 day for instance for a POSIX equivalent
    – Stéphane Chazelas
    Sep 10 at 18:00




    @ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better -depth 2 with NetBSD find. See delete folders older than 1 day for instance for a POSIX equivalent
    – Stéphane Chazelas
    Sep 10 at 18:00










    up vote
    0
    down vote













    Please note that find will search recursively in all the directories.

    Find will return not only files, but also directories!



    If you want to list all files within the test directory, all you need is the following command:
    find test/ -type f



    Also, I don't know what you are trying to achieve, but check your find manpage... You are using -exec ll ; and I suspect there's probably a find option that will do what you need (filter files by size, modification date, etc.)






    share|improve this answer
























      up vote
      0
      down vote













      Please note that find will search recursively in all the directories.

      Find will return not only files, but also directories!



      If you want to list all files within the test directory, all you need is the following command:
      find test/ -type f



      Also, I don't know what you are trying to achieve, but check your find manpage... You are using -exec ll ; and I suspect there's probably a find option that will do what you need (filter files by size, modification date, etc.)






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Please note that find will search recursively in all the directories.

        Find will return not only files, but also directories!



        If you want to list all files within the test directory, all you need is the following command:
        find test/ -type f



        Also, I don't know what you are trying to achieve, but check your find manpage... You are using -exec ll ; and I suspect there's probably a find option that will do what you need (filter files by size, modification date, etc.)






        share|improve this answer












        Please note that find will search recursively in all the directories.

        Find will return not only files, but also directories!



        If you want to list all files within the test directory, all you need is the following command:
        find test/ -type f



        Also, I don't know what you are trying to achieve, but check your find manpage... You are using -exec ll ; and I suspect there's probably a find option that will do what you need (filter files by size, modification date, etc.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 10 at 9:44









        pi0tr

        1202




        1202



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f467988%2ffind-exec-ll-with-just-one-result-instead-of-four%23new-answer', 'question_page');

            );

            Post as a guest













































































            這個網誌中的熱門文章

            Why am i infinitely getting the same tweet with the Twitter Search API?

            Is there any way to eliminate the singular point to solve this integral by hand or by approximations?

            Strongly p-embedded subgroups and p-Sylow subgroups.