I was trying to rename some files to another extension:
# mv *.sqlite3_done *.sqlite3
but got an error:
mv: target '*.sqlite3' is not a directory
Why?
I was trying to rename some files to another extension:
# mv *.sqlite3_done *.sqlite3
but got an error:
mv: target '*.sqlite3' is not a directory
Why?
mv
can only move multiple files into a single directory; it can’t move each one to a different name. You can loop in bash instead:
for x in *.sqlite3_done; do
mv -- "$x" "${x%_done}"
done
${x%_done}
removes _done
from the end of $x
.
the easy way is use find
find . -type f -name '*.sqlite3_done' -exec sh -c 'x="{}"; mv "$x" "${x%_done}"' \;
The wildcard expansion results in multiple names being passed to the command. The shell thinks you are trying to move multiple files to the *.sqlite3
directory.
You need to use a loop:
for nam in *sqlite3_done
do
newname=${nam%_done}
mv $nam $newname
done
The %_done
says to remove the last occurrence of _done
from the string.
If you may have spaces in your filenames you will want to quote the filenames.