30 lines
556 B
Bash
Executable File
30 lines
556 B
Bash
Executable File
#!/bin/bash
|
|
|
|
TDIR=$1 # terget dir
|
|
|
|
if [ -n "$TDIR ] && [ -d "$TDIR ]; then
|
|
for f in $TDIR # set a nice filter
|
|
do
|
|
new="${f// /_}" # defining "new"
|
|
if [ "$new" != "$f" ]; then
|
|
if [ -e "$new" ]; then
|
|
echo not renamed \""$f"\" because \""$new"\" already exists # already exist
|
|
|
|
else
|
|
echo rename "$f" as "$new" # "f" renamed to "new"
|
|
mv "$f" "$new" # rename
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# mv "$f" "`echo $f | tr ' ' '_'`"
|
|
done
|
|
|
|
fi
|
|
|
|
# fix the "_-_" problem
|
|
for f in $TDIR; do
|
|
mv "$f" $(echo "$f" | sed 's/_-_/_/g')
|
|
done
|