Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename files using wildcard in bash?

Tags:

bash

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?

like image 469
AngeloC Avatar asked Aug 16 '17 01:08

AngeloC


People also ask

How do I rename a file in bash?

You can use the built-in Linux command mv to rename files. Here are some of the options that can come in handy with the mv command: -v , --verbose : Explains what is being done. -i , --interactive : Prompts before renaming the file.


1 Answers

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.

like image 150
Ry- Avatar answered Sep 27 '22 21:09

Ry-