• Uncategorized

About linux : Listing-only-name-and-size-of-the-file-with-largest-size-UNIX-duplicate

Question Detail

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

Question Answer

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.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.