IFS="\n" # Handle files with spaces in the names
for file in ABS*; do
newfile="${file/ABS/ABS-}" # Add the hyphen following ABS
newfile="${newfile/_/-}" # Change the underscore to a hyphen
mv "$file" "$newfile" # Make the change
done
À luz dos comentários de Tony abaixo, uma versão de uso mais geral poderia ser a seguinte:
IFS="\n" # Handle files with spaces in the names
for file in ABS*; do
newfile="${file/foo/bar}" # Replace foo with bar
newfile="${newfile/baz/quux}" # Replace baz with quux (repeat as needed)
if [[ "$file" == "$newfile" ]]; then
echo "Not renaming $file - no change decreed."
elif [[ -f "$newfile" ]]; then
echo "Not renaming $file - $newfile already exists."
else
mv -- "$file" "$newfile" # Make the change
fi
done