Find files greater than X value, sort by size, show in ls format

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











up vote
0
down vote

favorite












I am extremely confused, since a command I'm rather confident in, returns something completely different than I imagine!



My assignment is simple: Find files (in a specific directory that is given) , show only the ones above 100 megabytes, sort them by size, print them in ls -lh format.



This is what I execute:



find /home/it21366 -size +10M | sort -h | ls -lh


This is what I get



-rwxr-xr-x+ 1 it21366 unixusers 12K Απρ 28 2014 a.out
-rwxr-xr-x+ 1 it21366 unixusers 471 Νοέ 29 10:51 askisi.sh
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c~
-rw-r--r--+ 1 it21366 unixusers 6,2K Απρ 28 2014 CODE.txt
-rw-------+ 1 it21366 unixusers 2,0M Απρ 28 2014 core
-rwxr-xr-x+ 1 it21366 unixusers 66 Δεκ 6 14:39 it21366_ex_1_1
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:35 it21366_ex_1_4.sh
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:27 it21366_ex_1_4.sh~
-rwxr-xr-x+ 1 it21366 unixusers 546 Δεκ 5 17:46 it21366_ex_1_5
-rw-r--r--+ 1 it21366 unixusers 509K Οκτ 23 2014 java01.pdf
-rw-r--r--+ 1 it21366 unixusers 506K Οκτ 23 2014 java02.pdf
-rw-r--r--+ 1 it21366 unixusers 249K Οκτ 11 10:03 lab01_2018-19.pdf
-rw-r--r--+ 1 it21366 unixusers 1,2K Οκτ 24 16:27 MyClock.java
-rw-r--r--+ 1 it21366 unixusers 1,3K Οκτ 30 2013 starthere.desktop
-rw-r--r--+ 1 it21366 unixusers 3 Οκτ 24 12:45 test
-rw-r--r--+ 1 it21366 unixusers 12 Οκτ 24 12:45 TK.txt
-rw-r--r--+ 1 it21366 unixusers 14K Μάι 30 2018 Untitled 1.odt


Indeed I am a beginner, but I can't imagine why LS seems to ignore the other methods, and simply shows the contents of the files unsorted and unfiltered.



I would greatly appreciate some insight, not necessarily a direct solution, just a small hint will do!



Thank you in advance!










share|improve this question





















  • ls does not use anything you're trying to pipe to it through standard input. Since its command line arguments are just the options -lh, it's listing the full contents of the current directory, in long format with human-optimized file sizes, in default alphanumeric sort order. You would need different options for ls to sort in different ways, e.g. by size, or to display the directory list unsorted.
    – telcoM
    Dec 6 at 12:56







  • 1




    Related: Pipe to ls Not Working as Expected
    – steeldriver
    Dec 6 at 13:00










  • Related: Sort the output of find -exec ls
    – Jeff Schaller
    Dec 6 at 13:39















up vote
0
down vote

favorite












I am extremely confused, since a command I'm rather confident in, returns something completely different than I imagine!



My assignment is simple: Find files (in a specific directory that is given) , show only the ones above 100 megabytes, sort them by size, print them in ls -lh format.



This is what I execute:



find /home/it21366 -size +10M | sort -h | ls -lh


This is what I get



-rwxr-xr-x+ 1 it21366 unixusers 12K Απρ 28 2014 a.out
-rwxr-xr-x+ 1 it21366 unixusers 471 Νοέ 29 10:51 askisi.sh
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c~
-rw-r--r--+ 1 it21366 unixusers 6,2K Απρ 28 2014 CODE.txt
-rw-------+ 1 it21366 unixusers 2,0M Απρ 28 2014 core
-rwxr-xr-x+ 1 it21366 unixusers 66 Δεκ 6 14:39 it21366_ex_1_1
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:35 it21366_ex_1_4.sh
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:27 it21366_ex_1_4.sh~
-rwxr-xr-x+ 1 it21366 unixusers 546 Δεκ 5 17:46 it21366_ex_1_5
-rw-r--r--+ 1 it21366 unixusers 509K Οκτ 23 2014 java01.pdf
-rw-r--r--+ 1 it21366 unixusers 506K Οκτ 23 2014 java02.pdf
-rw-r--r--+ 1 it21366 unixusers 249K Οκτ 11 10:03 lab01_2018-19.pdf
-rw-r--r--+ 1 it21366 unixusers 1,2K Οκτ 24 16:27 MyClock.java
-rw-r--r--+ 1 it21366 unixusers 1,3K Οκτ 30 2013 starthere.desktop
-rw-r--r--+ 1 it21366 unixusers 3 Οκτ 24 12:45 test
-rw-r--r--+ 1 it21366 unixusers 12 Οκτ 24 12:45 TK.txt
-rw-r--r--+ 1 it21366 unixusers 14K Μάι 30 2018 Untitled 1.odt


Indeed I am a beginner, but I can't imagine why LS seems to ignore the other methods, and simply shows the contents of the files unsorted and unfiltered.



I would greatly appreciate some insight, not necessarily a direct solution, just a small hint will do!



Thank you in advance!










share|improve this question





















  • ls does not use anything you're trying to pipe to it through standard input. Since its command line arguments are just the options -lh, it's listing the full contents of the current directory, in long format with human-optimized file sizes, in default alphanumeric sort order. You would need different options for ls to sort in different ways, e.g. by size, or to display the directory list unsorted.
    – telcoM
    Dec 6 at 12:56







  • 1




    Related: Pipe to ls Not Working as Expected
    – steeldriver
    Dec 6 at 13:00










  • Related: Sort the output of find -exec ls
    – Jeff Schaller
    Dec 6 at 13:39













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am extremely confused, since a command I'm rather confident in, returns something completely different than I imagine!



My assignment is simple: Find files (in a specific directory that is given) , show only the ones above 100 megabytes, sort them by size, print them in ls -lh format.



This is what I execute:



find /home/it21366 -size +10M | sort -h | ls -lh


This is what I get



-rwxr-xr-x+ 1 it21366 unixusers 12K Απρ 28 2014 a.out
-rwxr-xr-x+ 1 it21366 unixusers 471 Νοέ 29 10:51 askisi.sh
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c~
-rw-r--r--+ 1 it21366 unixusers 6,2K Απρ 28 2014 CODE.txt
-rw-------+ 1 it21366 unixusers 2,0M Απρ 28 2014 core
-rwxr-xr-x+ 1 it21366 unixusers 66 Δεκ 6 14:39 it21366_ex_1_1
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:35 it21366_ex_1_4.sh
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:27 it21366_ex_1_4.sh~
-rwxr-xr-x+ 1 it21366 unixusers 546 Δεκ 5 17:46 it21366_ex_1_5
-rw-r--r--+ 1 it21366 unixusers 509K Οκτ 23 2014 java01.pdf
-rw-r--r--+ 1 it21366 unixusers 506K Οκτ 23 2014 java02.pdf
-rw-r--r--+ 1 it21366 unixusers 249K Οκτ 11 10:03 lab01_2018-19.pdf
-rw-r--r--+ 1 it21366 unixusers 1,2K Οκτ 24 16:27 MyClock.java
-rw-r--r--+ 1 it21366 unixusers 1,3K Οκτ 30 2013 starthere.desktop
-rw-r--r--+ 1 it21366 unixusers 3 Οκτ 24 12:45 test
-rw-r--r--+ 1 it21366 unixusers 12 Οκτ 24 12:45 TK.txt
-rw-r--r--+ 1 it21366 unixusers 14K Μάι 30 2018 Untitled 1.odt


Indeed I am a beginner, but I can't imagine why LS seems to ignore the other methods, and simply shows the contents of the files unsorted and unfiltered.



I would greatly appreciate some insight, not necessarily a direct solution, just a small hint will do!



Thank you in advance!










share|improve this question













I am extremely confused, since a command I'm rather confident in, returns something completely different than I imagine!



My assignment is simple: Find files (in a specific directory that is given) , show only the ones above 100 megabytes, sort them by size, print them in ls -lh format.



This is what I execute:



find /home/it21366 -size +10M | sort -h | ls -lh


This is what I get



-rwxr-xr-x+ 1 it21366 unixusers 12K Απρ 28 2014 a.out
-rwxr-xr-x+ 1 it21366 unixusers 471 Νοέ 29 10:51 askisi.sh
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ 28 2014 code.c~
-rw-r--r--+ 1 it21366 unixusers 6,2K Απρ 28 2014 CODE.txt
-rw-------+ 1 it21366 unixusers 2,0M Απρ 28 2014 core
-rwxr-xr-x+ 1 it21366 unixusers 66 Δεκ 6 14:39 it21366_ex_1_1
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:35 it21366_ex_1_4.sh
-rwxr-xr-x+ 1 it21366 unixusers 190 Δεκ 6 14:27 it21366_ex_1_4.sh~
-rwxr-xr-x+ 1 it21366 unixusers 546 Δεκ 5 17:46 it21366_ex_1_5
-rw-r--r--+ 1 it21366 unixusers 509K Οκτ 23 2014 java01.pdf
-rw-r--r--+ 1 it21366 unixusers 506K Οκτ 23 2014 java02.pdf
-rw-r--r--+ 1 it21366 unixusers 249K Οκτ 11 10:03 lab01_2018-19.pdf
-rw-r--r--+ 1 it21366 unixusers 1,2K Οκτ 24 16:27 MyClock.java
-rw-r--r--+ 1 it21366 unixusers 1,3K Οκτ 30 2013 starthere.desktop
-rw-r--r--+ 1 it21366 unixusers 3 Οκτ 24 12:45 test
-rw-r--r--+ 1 it21366 unixusers 12 Οκτ 24 12:45 TK.txt
-rw-r--r--+ 1 it21366 unixusers 14K Μάι 30 2018 Untitled 1.odt


Indeed I am a beginner, but I can't imagine why LS seems to ignore the other methods, and simply shows the contents of the files unsorted and unfiltered.



I would greatly appreciate some insight, not necessarily a direct solution, just a small hint will do!



Thank you in advance!







find ls sort






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 6 at 12:48









Krow Caw

1




1











  • ls does not use anything you're trying to pipe to it through standard input. Since its command line arguments are just the options -lh, it's listing the full contents of the current directory, in long format with human-optimized file sizes, in default alphanumeric sort order. You would need different options for ls to sort in different ways, e.g. by size, or to display the directory list unsorted.
    – telcoM
    Dec 6 at 12:56







  • 1




    Related: Pipe to ls Not Working as Expected
    – steeldriver
    Dec 6 at 13:00










  • Related: Sort the output of find -exec ls
    – Jeff Schaller
    Dec 6 at 13:39

















  • ls does not use anything you're trying to pipe to it through standard input. Since its command line arguments are just the options -lh, it's listing the full contents of the current directory, in long format with human-optimized file sizes, in default alphanumeric sort order. You would need different options for ls to sort in different ways, e.g. by size, or to display the directory list unsorted.
    – telcoM
    Dec 6 at 12:56







  • 1




    Related: Pipe to ls Not Working as Expected
    – steeldriver
    Dec 6 at 13:00










  • Related: Sort the output of find -exec ls
    – Jeff Schaller
    Dec 6 at 13:39
















ls does not use anything you're trying to pipe to it through standard input. Since its command line arguments are just the options -lh, it's listing the full contents of the current directory, in long format with human-optimized file sizes, in default alphanumeric sort order. You would need different options for ls to sort in different ways, e.g. by size, or to display the directory list unsorted.
– telcoM
Dec 6 at 12:56





ls does not use anything you're trying to pipe to it through standard input. Since its command line arguments are just the options -lh, it's listing the full contents of the current directory, in long format with human-optimized file sizes, in default alphanumeric sort order. You would need different options for ls to sort in different ways, e.g. by size, or to display the directory list unsorted.
– telcoM
Dec 6 at 12:56





1




1




Related: Pipe to ls Not Working as Expected
– steeldriver
Dec 6 at 13:00




Related: Pipe to ls Not Working as Expected
– steeldriver
Dec 6 at 13:00












Related: Sort the output of find -exec ls
– Jeff Schaller
Dec 6 at 13:39





Related: Sort the output of find -exec ls
– Jeff Schaller
Dec 6 at 13:39











2 Answers
2






active

oldest

votes

















up vote
1
down vote













use xargs:



find /home/it21366 -size +10M | xargs ls -lhsSr 





share|improve this answer




















  • THANK YOU! Problem solved!
    – Krow Caw
    Dec 6 at 13:30










  • On the assumption that there are no files named with spaces or tabs in them
    – Jeff Schaller
    Dec 6 at 13:38

















up vote
1
down vote













Another option, if the number of files is limited enough to fit in one (long) call to ls, would be to use find to find the large files and ls -S to do the sorting:



find /home/it21366 -type f -size +10M -exec ls -lS + 2>/dev/null


The -exec ... + tells find to replace the "found" files into the call to ls, fitting as many as it can. If there are too many files, you'll get multiple calls to ls and thus un-sorted results (they'll be sorted in groups). I also added -type f to restrict the matches to regular files.






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: 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%2f486361%2ffind-files-greater-than-x-value-sort-by-size-show-in-ls-format%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








    up vote
    1
    down vote













    use xargs:



    find /home/it21366 -size +10M | xargs ls -lhsSr 





    share|improve this answer




















    • THANK YOU! Problem solved!
      – Krow Caw
      Dec 6 at 13:30










    • On the assumption that there are no files named with spaces or tabs in them
      – Jeff Schaller
      Dec 6 at 13:38














    up vote
    1
    down vote













    use xargs:



    find /home/it21366 -size +10M | xargs ls -lhsSr 





    share|improve this answer




















    • THANK YOU! Problem solved!
      – Krow Caw
      Dec 6 at 13:30










    • On the assumption that there are no files named with spaces or tabs in them
      – Jeff Schaller
      Dec 6 at 13:38












    up vote
    1
    down vote










    up vote
    1
    down vote









    use xargs:



    find /home/it21366 -size +10M | xargs ls -lhsSr 





    share|improve this answer












    use xargs:



    find /home/it21366 -size +10M | xargs ls -lhsSr 






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 6 at 12:51









    Ipor Sircer

    10.5k11024




    10.5k11024











    • THANK YOU! Problem solved!
      – Krow Caw
      Dec 6 at 13:30










    • On the assumption that there are no files named with spaces or tabs in them
      – Jeff Schaller
      Dec 6 at 13:38
















    • THANK YOU! Problem solved!
      – Krow Caw
      Dec 6 at 13:30










    • On the assumption that there are no files named with spaces or tabs in them
      – Jeff Schaller
      Dec 6 at 13:38















    THANK YOU! Problem solved!
    – Krow Caw
    Dec 6 at 13:30




    THANK YOU! Problem solved!
    – Krow Caw
    Dec 6 at 13:30












    On the assumption that there are no files named with spaces or tabs in them
    – Jeff Schaller
    Dec 6 at 13:38




    On the assumption that there are no files named with spaces or tabs in them
    – Jeff Schaller
    Dec 6 at 13:38












    up vote
    1
    down vote













    Another option, if the number of files is limited enough to fit in one (long) call to ls, would be to use find to find the large files and ls -S to do the sorting:



    find /home/it21366 -type f -size +10M -exec ls -lS + 2>/dev/null


    The -exec ... + tells find to replace the "found" files into the call to ls, fitting as many as it can. If there are too many files, you'll get multiple calls to ls and thus un-sorted results (they'll be sorted in groups). I also added -type f to restrict the matches to regular files.






    share|improve this answer
























      up vote
      1
      down vote













      Another option, if the number of files is limited enough to fit in one (long) call to ls, would be to use find to find the large files and ls -S to do the sorting:



      find /home/it21366 -type f -size +10M -exec ls -lS + 2>/dev/null


      The -exec ... + tells find to replace the "found" files into the call to ls, fitting as many as it can. If there are too many files, you'll get multiple calls to ls and thus un-sorted results (they'll be sorted in groups). I also added -type f to restrict the matches to regular files.






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        Another option, if the number of files is limited enough to fit in one (long) call to ls, would be to use find to find the large files and ls -S to do the sorting:



        find /home/it21366 -type f -size +10M -exec ls -lS + 2>/dev/null


        The -exec ... + tells find to replace the "found" files into the call to ls, fitting as many as it can. If there are too many files, you'll get multiple calls to ls and thus un-sorted results (they'll be sorted in groups). I also added -type f to restrict the matches to regular files.






        share|improve this answer












        Another option, if the number of files is limited enough to fit in one (long) call to ls, would be to use find to find the large files and ls -S to do the sorting:



        find /home/it21366 -type f -size +10M -exec ls -lS + 2>/dev/null


        The -exec ... + tells find to replace the "found" files into the call to ls, fitting as many as it can. If there are too many files, you'll get multiple calls to ls and thus un-sorted results (they'll be sorted in groups). I also added -type f to restrict the matches to regular files.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 at 13:37









        Jeff Schaller

        37.9k1053123




        37.9k1053123



























            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%2f486361%2ffind-files-greater-than-x-value-sort-by-size-show-in-ls-format%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

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

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay