I've already read through and tried many of the answers here for how to rename files with spaces in a nested directory structure. However, they do not seem to work for my situation. They all segfault.
I have just shy of 1,000,000 files in a directory structure of 32,768 directories. This is also on Windows (Server 2008 R2), and I'm running MINGW32 giving me Bash 3.1.
The directories are within a structure like 00/00/file1 01/00/file2 where each sub-directory "series" varies from 00 to zz. I believe the directory structure only goes 2 levels deep, but I could be wrong. Generating a file count from Windows Explorer's "properties" takes about 45 minutes.
I'm thinking the posted answers here are segfaulting because they are running out of memory building or walking these directories. This is my last attempt before posting here:
find . -maxdepth -1 -mindepth 1 -type -d -printf '%p\n' |
while IFS= read -r g; do
find "$g" -depth -name '* *' | while IFS= read -r f ; do
mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)
done
done
My last attempt tries walking into at least the first level of subdirectories and then using this solution from another post on this topic:
find . -depth -name '* *' | while IFS= read -r f ; do
mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)
done
Where you can see my version is simply that other post's answer embedded in an outer find loop. However, this also segfaults. I thought to try this because trying the above solution when one directory level in worked.
Create this shell script e.g. ./move.sh:
#!/bin/bash
echo mv "$1" "${1// /_}"
Make it executable.
Run:
find . -depth -name '* *' -exec ./move.sh "{}" \;
If output is okay, remove echo
from ./move.sh