unix move command regex
问题 I have a bunch of files in the format blahblah1.java.bak , blahblah2.java.bak , etc. And I want to change all the files ending with .bak to just .java . Is it possible to do this using the mv command? Perhaps something like mv (.*\.java)\.bak $1 ? 回答1: What's wrong with for i in *java.bak ; do mv "$i" `basename "$i" .bak` ; done or for i in *java.bak ; do mv "$i" "${i%.bak}" ; done if you are in bash. Command line file matching is not exactly the same as a regex in, say, Perl or =~ comparison