Skip to content

Instantly share code, notes, and snippets.

@Graham42
Created October 22, 2016 20:39
Show Gist options
  • Save Graham42/2ed13f473f1a47106e7aaebf99df43d3 to your computer and use it in GitHub Desktop.
Save Graham42/2ed13f473f1a47106e7aaebf99df43d3 to your computer and use it in GitHub Desktop.
Bash functions to run commands in all sub directories
# 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