Bash - How to find the longest txt file in a folder? [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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
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.
add a comment |
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
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
add a comment |
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
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
bash scripting
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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/://')
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
edited Mar 17 at 21:08
answered Mar 17 at 19:25
JuanJuan
201210
201210
add a comment |
add a comment |
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/://')
add a comment |
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/://')
add a comment |
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/://')
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/://')
edited Mar 17 at 19:37
Jeff Schaller♦
45k1164147
45k1164147
answered Mar 17 at 19:29
Mark ScheckMark Scheck
167
167
add a comment |
add a comment |
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