Apply command to all folders in Linux

Today in the office I was working on the OpenTele project and had to update all of my folders mapping the repositories from Bitbucket.  I was getting tired, just thinking about going into each folder manually and updating the repositories – so I thought that there must be a way on the command prompt to do it.. after a little search on the net I found the solution:

find . -type d -name .git -execdir git pull \;

The logic behind it is:

find

The command that is used for finding files

.

The names to match in the search

-type d

Find folders (directories)

-name .git

Where the content has the name “.git”.

-execdir git pull

In the folders where .git is found, switch to that folder and execute “git pull”

/;

This marks the end of the command (“/;” won’t be executed)

If you are in doubt or want to test the command, try using “echo” in front of it.  You can also use “{}” on the command line to insert the path of the current directory/folder

Leave a Reply

Your email address will not be published. Required fields are marked *

+ sixty six = seventy one