-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrename.sh
More file actions
executable file
·32 lines (26 loc) · 775 Bytes
/
rename.sh
File metadata and controls
executable file
·32 lines (26 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
# first, we fix the directories
for name in $(find . -type d -print | sed 's/ /____/g')
do
if [ $name != "." ] ; then
oldname="$(echo $name | sed 's/____/ /g')"
newname="$(echo $name | sed 's/____/_/g')"
if [ "$oldname" != "$newname" ] ; then
echo "renaming \"$oldname\" to $newname"
mv "$oldname" "$newname"
fi
fi
done
echo ""
echo "done with directories, fixing individual files..."
# now let's fix the files therein using almost identical code
for name in $(find . -type f -print | sed 's/ /____/g')
do
oldname="$(echo $name | sed 's/____/ /g')"
newname="$(echo $name | sed 's/____/_/g')"
if [ "$oldname" != "$newname" ] ; then
echo "renaming \"$oldname\" to $newname"
mv "$oldname" "$newname"
fi
done
exit 0