Quickest way to find the largest file in a directory and subdirectories [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:



  • Finding largest file recursively

    4 answers



I need to find the largest file in the current and subsequent directory. I tried



ls -Rlh | awk 'print $3 " " $5 " " $9' 


but do not know if it is ok, how to sort and select the largest file.







share|improve this question














marked as duplicate by Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 20 '17 at 17:13


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.


















    up vote
    0
    down vote

    favorite













    This question already has an answer here:



    • Finding largest file recursively

      4 answers



    I need to find the largest file in the current and subsequent directory. I tried



    ls -Rlh | awk 'print $3 " " $5 " " $9' 


    but do not know if it is ok, how to sort and select the largest file.







    share|improve this question














    marked as duplicate by Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas shell-script
    Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Nov 20 '17 at 17:13


    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.
















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:



      • Finding largest file recursively

        4 answers



      I need to find the largest file in the current and subsequent directory. I tried



      ls -Rlh | awk 'print $3 " " $5 " " $9' 


      but do not know if it is ok, how to sort and select the largest file.







      share|improve this question















      This question already has an answer here:



      • Finding largest file recursively

        4 answers



      I need to find the largest file in the current and subsequent directory. I tried



      ls -Rlh | awk 'print $3 " " $5 " " $9' 


      but do not know if it is ok, how to sort and select the largest file.





      This question already has an answer here:



      • Finding largest file recursively

        4 answers









      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '17 at 15:37









      Archemar

      19k93366




      19k93366










      asked Nov 20 '17 at 15:22









      Alex

      1104




      1104




      marked as duplicate by Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas shell-script
      Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Nov 20 '17 at 17:13


      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 Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas shell-script
      Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Nov 20 '17 at 17:13


      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.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:



          find . -type f -printf "%s %pn" | sort -nr | head -1



          • %s - format specificator pointing to file size (in bytes)


          • %p - format specificator pointing to file name


          • sort -nr - sort records numerically in reversed order


          • head -1 - print the TOP first line/record


          To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):



          find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si





          share|improve this answer






















          • I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, se my update
            – RomanPerekhrest
            Nov 20 '17 at 16:33










          • Worked perfect! I didn't know there is an actual function for converting to human readable
            – Alex
            Nov 20 '17 at 17:19

















          up vote
          0
          down vote













          With zsh, for the biggest regular file:



          ls -ld -- **/*(.DOL[1])


          (of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)




          • .: only regular files (not directories, symlinks, devices, fifos...)


          • D: include hidden ones and descend into hidden dirs


          • OL: reverse-ordered by size (Length).


          • [1]: only the first match.

          If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.






          share|improve this answer






















          • I might do something wrong but it does not work
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, I suspect you missed the "With zsh" part. What shell are you trying it in? In which way does it not work?
            – Stéphane Chazelas
            Nov 20 '17 at 16:16











          • I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
            – Alex
            Nov 20 '17 at 16:29










          • From bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).
            – Stéphane Chazelas
            Nov 20 '17 at 16:32


















          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:



          find . -type f -printf "%s %pn" | sort -nr | head -1



          • %s - format specificator pointing to file size (in bytes)


          • %p - format specificator pointing to file name


          • sort -nr - sort records numerically in reversed order


          • head -1 - print the TOP first line/record


          To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):



          find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si





          share|improve this answer






















          • I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, se my update
            – RomanPerekhrest
            Nov 20 '17 at 16:33










          • Worked perfect! I didn't know there is an actual function for converting to human readable
            – Alex
            Nov 20 '17 at 17:19














          up vote
          2
          down vote



          accepted










          GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:



          find . -type f -printf "%s %pn" | sort -nr | head -1



          • %s - format specificator pointing to file size (in bytes)


          • %p - format specificator pointing to file name


          • sort -nr - sort records numerically in reversed order


          • head -1 - print the TOP first line/record


          To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):



          find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si





          share|improve this answer






















          • I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, se my update
            – RomanPerekhrest
            Nov 20 '17 at 16:33










          • Worked perfect! I didn't know there is an actual function for converting to human readable
            – Alex
            Nov 20 '17 at 17:19












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:



          find . -type f -printf "%s %pn" | sort -nr | head -1



          • %s - format specificator pointing to file size (in bytes)


          • %p - format specificator pointing to file name


          • sort -nr - sort records numerically in reversed order


          • head -1 - print the TOP first line/record


          To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):



          find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si





          share|improve this answer














          GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:



          find . -type f -printf "%s %pn" | sort -nr | head -1



          • %s - format specificator pointing to file size (in bytes)


          • %p - format specificator pointing to file name


          • sort -nr - sort records numerically in reversed order


          • head -1 - print the TOP first line/record


          To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):



          find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '17 at 16:32

























          answered Nov 20 '17 at 15:27









          RomanPerekhrest

          22.4k12145




          22.4k12145











          • I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, se my update
            – RomanPerekhrest
            Nov 20 '17 at 16:33










          • Worked perfect! I didn't know there is an actual function for converting to human readable
            – Alex
            Nov 20 '17 at 17:19
















          • I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, se my update
            – RomanPerekhrest
            Nov 20 '17 at 16:33










          • Worked perfect! I didn't know there is an actual function for converting to human readable
            – Alex
            Nov 20 '17 at 17:19















          I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
          – Alex
          Nov 20 '17 at 16:12




          I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
          – Alex
          Nov 20 '17 at 16:12












          @JamesW, se my update
          – RomanPerekhrest
          Nov 20 '17 at 16:33




          @JamesW, se my update
          – RomanPerekhrest
          Nov 20 '17 at 16:33












          Worked perfect! I didn't know there is an actual function for converting to human readable
          – Alex
          Nov 20 '17 at 17:19




          Worked perfect! I didn't know there is an actual function for converting to human readable
          – Alex
          Nov 20 '17 at 17:19












          up vote
          0
          down vote













          With zsh, for the biggest regular file:



          ls -ld -- **/*(.DOL[1])


          (of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)




          • .: only regular files (not directories, symlinks, devices, fifos...)


          • D: include hidden ones and descend into hidden dirs


          • OL: reverse-ordered by size (Length).


          • [1]: only the first match.

          If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.






          share|improve this answer






















          • I might do something wrong but it does not work
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, I suspect you missed the "With zsh" part. What shell are you trying it in? In which way does it not work?
            – Stéphane Chazelas
            Nov 20 '17 at 16:16











          • I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
            – Alex
            Nov 20 '17 at 16:29










          • From bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).
            – Stéphane Chazelas
            Nov 20 '17 at 16:32















          up vote
          0
          down vote













          With zsh, for the biggest regular file:



          ls -ld -- **/*(.DOL[1])


          (of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)




          • .: only regular files (not directories, symlinks, devices, fifos...)


          • D: include hidden ones and descend into hidden dirs


          • OL: reverse-ordered by size (Length).


          • [1]: only the first match.

          If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.






          share|improve this answer






















          • I might do something wrong but it does not work
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, I suspect you missed the "With zsh" part. What shell are you trying it in? In which way does it not work?
            – Stéphane Chazelas
            Nov 20 '17 at 16:16











          • I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
            – Alex
            Nov 20 '17 at 16:29










          • From bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).
            – Stéphane Chazelas
            Nov 20 '17 at 16:32













          up vote
          0
          down vote










          up vote
          0
          down vote









          With zsh, for the biggest regular file:



          ls -ld -- **/*(.DOL[1])


          (of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)




          • .: only regular files (not directories, symlinks, devices, fifos...)


          • D: include hidden ones and descend into hidden dirs


          • OL: reverse-ordered by size (Length).


          • [1]: only the first match.

          If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.






          share|improve this answer














          With zsh, for the biggest regular file:



          ls -ld -- **/*(.DOL[1])


          (of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)




          • .: only regular files (not directories, symlinks, devices, fifos...)


          • D: include hidden ones and descend into hidden dirs


          • OL: reverse-ordered by size (Length).


          • [1]: only the first match.

          If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '17 at 16:34

























          answered Nov 20 '17 at 16:00









          Stéphane Chazelas

          282k53521854




          282k53521854











          • I might do something wrong but it does not work
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, I suspect you missed the "With zsh" part. What shell are you trying it in? In which way does it not work?
            – Stéphane Chazelas
            Nov 20 '17 at 16:16











          • I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
            – Alex
            Nov 20 '17 at 16:29










          • From bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).
            – Stéphane Chazelas
            Nov 20 '17 at 16:32

















          • I might do something wrong but it does not work
            – Alex
            Nov 20 '17 at 16:12










          • @JamesW, I suspect you missed the "With zsh" part. What shell are you trying it in? In which way does it not work?
            – Stéphane Chazelas
            Nov 20 '17 at 16:16











          • I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
            – Alex
            Nov 20 '17 at 16:29










          • From bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).
            – Stéphane Chazelas
            Nov 20 '17 at 16:32
















          I might do something wrong but it does not work
          – Alex
          Nov 20 '17 at 16:12




          I might do something wrong but it does not work
          – Alex
          Nov 20 '17 at 16:12












          @JamesW, I suspect you missed the "With zsh" part. What shell are you trying it in? In which way does it not work?
          – Stéphane Chazelas
          Nov 20 '17 at 16:16





          @JamesW, I suspect you missed the "With zsh" part. What shell are you trying it in? In which way does it not work?
          – Stéphane Chazelas
          Nov 20 '17 at 16:16













          I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
          – Alex
          Nov 20 '17 at 16:29




          I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
          – Alex
          Nov 20 '17 at 16:29












          From bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).
          – Stéphane Chazelas
          Nov 20 '17 at 16:32





          From bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).
          – Stéphane Chazelas
          Nov 20 '17 at 16:32



          Popular posts from this blog

          Peggy Mitchell

          The Forum (Inglewood, California)

          Palaiologos