Skip to main content

How would you use a Bash script to find the largest file in a directory and its size?

I would use the ‘find’ command combined with ‘du’ to list all files and then pipe that output to ‘sort’ and ‘head’ to get the largest file. For example, ‘find…

HW
How would you use a Bash script to find the largest file in a directory and its size?

COVER // HOW WOULD YOU USE A BASH SCRIPT TO FIND THE LARGEST FILE IN A DIRECTORY AND ITS SIZE?

I would use the ‘find’ command combined with ‘du’ to list all files and then pipe that output to ‘sort’ and ‘head’ to get the largest file. For example, ‘find . -type f -exec du -h {} + | sort -rh | head -n 1’.

Let's Talk

Have a Project in Mind?

Whether it's a software challenge, an AI integration, or a course enquiry — I'm always open to a real conversation.

hello@debasisbhattacharjee.com · +91 8777088548 · Mon–Fri, 9AM–6PM IST