Skip to content

backendorf/run-on-each

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

run-on-each

A tiny Bash helper to run a single command in each immediate subdirectory of the current folder.

Features

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

Requirements

  • bash
  • find and tput (commonly available on most Linux/macOS systems)

Usage

  1. Make the script executable (once): chmod +x run.sh
  2. From the parent directory of the targets, run: ./run.sh "your command here"

Examples

  • 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"

Notes

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

About

Run command on each child directory

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages