Skip to content

chrisreddington/learning-bash-rdt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Count files by extension and print a sorted summary

Language: bash
Difficulty: intermediate

Challenge Description

Create a portable Bash script (file-ext-summary.sh) that counts regular files grouped by file extension in a target directory and prints a sorted summary. Requirements:

  • Usage: ./file-ext-summary.sh [-r] [directory]
    • If directory omitted, default to current working directory.
    • -r enables recursive search.
    • -h|--help prints usage and exits.
  • Treat filenames with spaces and special characters correctly.
  • Group extensions case-insensitively (e.g., .MD and .md count together).
  • Files without an extension should be counted under the label "no_extension".
  • Output should be sorted by descending count, one entry per line: COUNT EXTENSION (e.g. "42 md").
  • Exit with non-zero on error and print helpful errors.

Hints: use find -print0 and a while loop (IFS= read -r -d '' file); use parameter expansion or awk to extract extensions; aggregate with awk/sort/uniq -c.

Solution Files

  • solution.sh

Evaluation Summary

Strong solution with solid logic, but hidden file duplication bug in fallback path when -maxdepth unsupported.

How to Run

# Clone the repository
git clone <this-repo-url>
cd <repo-name>

# Run the solution (adjust based on language)
# TypeScript: npx ts-node solution.ts
# Python: python solution.py
# Java: javac Solution.java && java Solution

Exported from Flight School using GitHub Copilot SDK

About

Pushing live, what can go wrong!

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages