# Specify the root directory where you want to start the search root_dir="$1" # Takes the root directory as a command-line argument
# Function to check and add index.html add_index_html() { local dir=$1
# Check if index.php or index.html already exists in the directory if [[ ! -f "$dir/index.php" && ! -f "$dir/index.html" ]]; then echo "Adding index.html in $dir"
# Create the custom index.html with 404 title and blank content cat <<EOF > "$dir/index.html" <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>404</title> </head> <body> </body> </html> EOF fi }
# Export function for use with find command export -f add_index_html
# Start from the root directory and find all subdirectories find "$root_dir" -type d -exec bash -c 'add_index_html "$0"' {} \;