cswork / libraryOpen practice workspace

Interview questions · Others

Return the largest file size in a directory

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).

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.

Community answers

Nothing here yet.

Join in on CSWork →