Bash - How to find the longest txt file in a folder? [closed]

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-5















I need to write a script which finds the longest txt file in a folder. I literally have no idea how to do it










share|improve this question















closed as unclear what you're asking by Ipor Sircer, Jeff Schaller, Kusalananda, ilkkachu, Rui F Ribeiro Mar 18 at 0:35


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • What do you mean by "the longest text file"?

    – Nasir Riley
    Mar 17 at 19:09











  • Largest in size or longest filename? What designates a "txt" file -- a ".txt" at the end of the filename?

    – Jeff Schaller
    Mar 17 at 19:27






  • 2





    Longest in terms of what? Bytes? Characters? Lines? Have you determined how to find out the length of a file?

    – ilkkachu
    Mar 17 at 19:29

















-5















I need to write a script which finds the longest txt file in a folder. I literally have no idea how to do it










share|improve this question















closed as unclear what you're asking by Ipor Sircer, Jeff Schaller, Kusalananda, ilkkachu, Rui F Ribeiro Mar 18 at 0:35


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • What do you mean by "the longest text file"?

    – Nasir Riley
    Mar 17 at 19:09











  • Largest in size or longest filename? What designates a "txt" file -- a ".txt" at the end of the filename?

    – Jeff Schaller
    Mar 17 at 19:27






  • 2





    Longest in terms of what? Bytes? Characters? Lines? Have you determined how to find out the length of a file?

    – ilkkachu
    Mar 17 at 19:29













-5












-5








-5








I need to write a script which finds the longest txt file in a folder. I literally have no idea how to do it










share|improve this question
















I need to write a script which finds the longest txt file in a folder. I literally have no idea how to do it







bash scripting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 18 at 0:36









Rui F Ribeiro

42.1k1483142




42.1k1483142










asked Mar 17 at 18:58









Atesz01Atesz01

1




1




closed as unclear what you're asking by Ipor Sircer, Jeff Schaller, Kusalananda, ilkkachu, Rui F Ribeiro Mar 18 at 0:35


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Ipor Sircer, Jeff Schaller, Kusalananda, ilkkachu, Rui F Ribeiro Mar 18 at 0:35


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • What do you mean by "the longest text file"?

    – Nasir Riley
    Mar 17 at 19:09











  • Largest in size or longest filename? What designates a "txt" file -- a ".txt" at the end of the filename?

    – Jeff Schaller
    Mar 17 at 19:27






  • 2





    Longest in terms of what? Bytes? Characters? Lines? Have you determined how to find out the length of a file?

    – ilkkachu
    Mar 17 at 19:29

















  • What do you mean by "the longest text file"?

    – Nasir Riley
    Mar 17 at 19:09











  • Largest in size or longest filename? What designates a "txt" file -- a ".txt" at the end of the filename?

    – Jeff Schaller
    Mar 17 at 19:27






  • 2





    Longest in terms of what? Bytes? Characters? Lines? Have you determined how to find out the length of a file?

    – ilkkachu
    Mar 17 at 19:29
















What do you mean by "the longest text file"?

– Nasir Riley
Mar 17 at 19:09





What do you mean by "the longest text file"?

– Nasir Riley
Mar 17 at 19:09













Largest in size or longest filename? What designates a "txt" file -- a ".txt" at the end of the filename?

– Jeff Schaller
Mar 17 at 19:27





Largest in size or longest filename? What designates a "txt" file -- a ".txt" at the end of the filename?

– Jeff Schaller
Mar 17 at 19:27




2




2





Longest in terms of what? Bytes? Characters? Lines? Have you determined how to find out the length of a file?

– ilkkachu
Mar 17 at 19:29





Longest in terms of what? Bytes? Characters? Lines? Have you determined how to find out the length of a file?

– ilkkachu
Mar 17 at 19:29










2 Answers
2






active

oldest

votes


















1














If I understood it correctly:



Assuming all the files has TXT extension, you can do



du -b *.txt | sort -n | tail -n1



and if you want something a little bit more specific:



for a in *;do
f=$( file -i $a | grep -Eo ": ([a-z/]+);" )
[ "$f" == ": text/plain;" ] && du -b $a
done | sort -n | tail -n 1





share|improve this answer
































    0














    Are there other files in the directory? Can you give us the directory listing?



    But barring that I would try something like



    ls -Sl $(file * |grep text |cut -d " " -f 1|sed 's/://')





    share|improve this answer































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      If I understood it correctly:



      Assuming all the files has TXT extension, you can do



      du -b *.txt | sort -n | tail -n1



      and if you want something a little bit more specific:



      for a in *;do
      f=$( file -i $a | grep -Eo ": ([a-z/]+);" )
      [ "$f" == ": text/plain;" ] && du -b $a
      done | sort -n | tail -n 1





      share|improve this answer





























        1














        If I understood it correctly:



        Assuming all the files has TXT extension, you can do



        du -b *.txt | sort -n | tail -n1



        and if you want something a little bit more specific:



        for a in *;do
        f=$( file -i $a | grep -Eo ": ([a-z/]+);" )
        [ "$f" == ": text/plain;" ] && du -b $a
        done | sort -n | tail -n 1





        share|improve this answer



























          1












          1








          1







          If I understood it correctly:



          Assuming all the files has TXT extension, you can do



          du -b *.txt | sort -n | tail -n1



          and if you want something a little bit more specific:



          for a in *;do
          f=$( file -i $a | grep -Eo ": ([a-z/]+);" )
          [ "$f" == ": text/plain;" ] && du -b $a
          done | sort -n | tail -n 1





          share|improve this answer















          If I understood it correctly:



          Assuming all the files has TXT extension, you can do



          du -b *.txt | sort -n | tail -n1



          and if you want something a little bit more specific:



          for a in *;do
          f=$( file -i $a | grep -Eo ": ([a-z/]+);" )
          [ "$f" == ": text/plain;" ] && du -b $a
          done | sort -n | tail -n 1






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 17 at 21:08

























          answered Mar 17 at 19:25









          JuanJuan

          201210




          201210























              0














              Are there other files in the directory? Can you give us the directory listing?



              But barring that I would try something like



              ls -Sl $(file * |grep text |cut -d " " -f 1|sed 's/://')





              share|improve this answer





























                0














                Are there other files in the directory? Can you give us the directory listing?



                But barring that I would try something like



                ls -Sl $(file * |grep text |cut -d " " -f 1|sed 's/://')





                share|improve this answer



























                  0












                  0








                  0







                  Are there other files in the directory? Can you give us the directory listing?



                  But barring that I would try something like



                  ls -Sl $(file * |grep text |cut -d " " -f 1|sed 's/://')





                  share|improve this answer















                  Are there other files in the directory? Can you give us the directory listing?



                  But barring that I would try something like



                  ls -Sl $(file * |grep text |cut -d " " -f 1|sed 's/://')






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 17 at 19:37









                  Jeff Schaller

                  45k1164147




                  45k1164147










                  answered Mar 17 at 19:29









                  Mark ScheckMark Scheck

                  167




                  167












                      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