2024-04-16 17:22:16 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2024-04-16 18:50:45 +03:00
|
|
|
# Finds all files in a directory and renames all spaces to '_'.
|
2024-04-16 17:22:16 +03:00
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
ROOT_DIR="${1:-}"
|
|
|
|
|
|
|
|
if [ -z "$ROOT_DIR" ]; then
|
2024-04-16 18:24:58 +03:00
|
|
|
echo "Usage: $0 <directory>"
|
|
|
|
exit 1
|
2024-04-16 17:22:16 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
find "$ROOT_DIR" -type f -name '*' -print0 | while IFS= read -r -d '' file; do
|
2024-04-16 18:50:45 +03:00
|
|
|
new_file="$(echo "$file" | tr ' ' '_')"
|
2024-04-16 18:24:58 +03:00
|
|
|
if [[ "$file" != "$new_file" ]]; then
|
|
|
|
mv -v "$file" "$new_file"
|
|
|
|
fi
|
2024-04-16 17:22:16 +03:00
|
|
|
done
|