Created
October 22, 2016 20:39
-
-
Save Graham42/2ed13f473f1a47106e7aaebf99df43d3 to your computer and use it in GitHub Desktop.
Bash functions to run commands in all sub directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# do something in each subfolder, excludes hidden folders | |
function foreach_dir(){ | |
for arg in $(ls --color=none); do | |
if [ -d "$arg" ] ; then | |
cd $arg | |
eval $@ | |
cd .. | |
fi | |
done | |
} | |
# do something in each subfolder in parralell, excludes hidden folders | |
function foreach_dir-threaded(){ | |
for arg in $(ls --color=none); do | |
if [ -d "$arg" ] ; then | |
cd $arg | |
$@ >/dev/null 2>&1 & | |
cd .. | |
fi | |
done | |
echo "Started..." | |
wait | |
echo "Done!" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment