Here’s a quick bash script that will cd into each directory (in your current directory) and run php artisan optimize:clear
if artisan
exists in that directory.
One-liner (Run from your parent directory):
for dir in */; do
if [ -f "$dir/artisan" ]; then
echo "Running optimize:clear in $dir"
cd "$dir"
php artisan optimize:clear
cd ..
else
echo "Skipping $dir (no artisan found)"
fi
done
Copy-paste Full Script:
#!/bin/bash
for dir in */; do
if [ -f "${dir}artisan" ]; then
echo "Running optimize:clear in $dir"
(cd "$dir" && php artisan optimize:clear)
else
echo "Skipping $dir (no artisan found)"
fi
done
- Save as
optimize_all.sh
, chmod +x optimize_all.sh
, and run with ./optimize_all.sh
.
This will:
- Go into each directory.
- Run
php artisan optimize:clear
if artisan
exists.
- Print what it’s doing.
- Skip directories that aren’t Laravel projects.
Let me know if you want to target only specific folders or add logging/output to a file!