Return the largest file size in a directory

Read the full interview experience this question came from →

Quick Overview

This question evaluates shell scripting and filesystem manipulation skills, specifically recursive file traversal and file metadata handling using Unix command-line tools, and belongs to the Coding & Algorithms domain (Bash/File System).

Return the largest file size in a directory

Company: Others

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Online Assessment

## Problem (Bash / File System) Implement a Bash function (or shell snippet) that returns the **maximum file size** (in bytes) under a given directory. ### Requirements - Input: a directory path `DIR` - Consider **regular files only** (ignore directories; you may ignore symlinks unless you explicitly choose to follow them) - Search **recursively** under `DIR` - Output: a single integer = the size (bytes) of the largest file found - If there are no regular files, output `0` ### Example If `DIR` contains files of sizes 10, 25, and 7 bytes (possibly in subdirectories), output `25`.

Overview: This question evaluates shell scripting and filesystem manipulation skills, specifically recursive file traversal and file metadata handling using Unix command-line tools, and belongs to the Coding & Algorithms domain (Bash/File System).

Read the full Others Data Scientist interview experience this question came from

|Home/Coding & Algorithms/Others
O
Others
Jan 17, 2026
easyData ScientistOnline AssessmentCoding & Algorithms
9
0

Problem (Bash / File System)

Implement a Bash function (or shell snippet) that returns the maximum file size (in bytes) under a given directory.

Requirements

  • Input: a directory path DIR
  • Consider regular files only (ignore directories; you may ignore symlinks unless you explicitly choose to follow them)
  • Search recursively under DIR
  • Output: a single integer = the size (bytes) of the largest file found
  • If there are no regular files, output 0

Example

If DIR contains files of sizes 10, 25, and 7 bytes (possibly in subdirectories), output 25.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...