-1

How can I only list the name and the size of the largest file size in a directory I used this command but It didn't work when I tried on a different directories.

find . -type f -exec ls -lS {} \; | sort -t" " -n -k5 | cut -d" " -f5,10 | tail -n1
r0B0T_99
  • 3
  • 2

1 Answers1

0

This should work

find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head -n 1

the number 1 after head -n means how many of the largest files it'll output and if you want to find files in sub-directories as well you can do that by removing the -maxdepth 1 or changing the number to a larger one.

for more info see the replies in this earlier post: How to find the largest file in a directory and its subdirectories?

For posts about this kind of stuff i suggest tagging them as bash, sh or shell.

  • Please don't answer duplicates; instead, leave a comment indicating that the question is a duplicate. Once you earn enough reputation points, you will also be able to participate in voting to close as a duplicate (and eventually, if you earn a gold badge in one of the tags, you can unilaterally close as a duplicate, like I did here). – tripleee Jan 09 '22 at 11:34