A tiny Bash helper to run a single command in each immediate subdirectory of the current folder.
- Executes your command in every immediate child directory (one level deep).
- Prints each directory name in green before running your command.
- Always returns to the original directory when finished.
- Skips directories it cannot enter.
- bash
- find and tput (commonly available on most Linux/macOS systems)
- Make the script executable (once): chmod +x run.sh
- From the parent directory of the targets, run: ./run.sh "your command here"
- Update many Git repos: ./run.sh "git checkout main && git pull --ff-only"
- Install Node dependencies across projects: ./run.sh "npm ci"
- Check Python version in each subdirectory: ./run.sh "python3 --version"
- Quote the command so it is passed as a single argument.
- The command runs with the working directory set to each subdirectory.
- Only immediate subdirectories are processed (no recursion).
- If a command fails in one directory, the script continues with the next.