Home » Questions » Computers [ Ask a new question ]

Looping Through Subdirectories and Running a Command in Each

Looping Through Subdirectories and Running a Command in Each

I have a set of repositories sorted into directories based on their VCS (Git, Mercurial, SVN). With Subversion I was able to run svn update * in the parent directory and it would loop through each directory and update each repository as expected. That's not the case for Git or Mercurial.

Asked by: Guest | Views: 320
Total answers/comments: 2
Guest [Entry]

for dir in ~/projects/git/*; do (cd "$dir" && git pull); done
Guest [Entry]

"If you have GNU Parallel http:// www.gnudotorg/software/parallel/ installed you can do this:

cd ~/projects/git/; ls | parallel 'cd {} && git pull'

This will run in parallel so if some of the git servers' network connection are slow this may speed up things.

Watch the intro video for GNU Parallel to learn more:
http://www.youtube.com/watch?v=OpaiGYxkSuQ"