I need to write a script which finds the longest txt file in a folder. I literally have no idea how to do it
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.
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
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/://')