unix move command regex

百般思念 提交于 2019-12-11 16:43:53

问题


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 in bash and you cannot capture a group. Note the differences: for example, * and . have a very different meaning.



来源:https://stackoverflow.com/questions/17554092/unix-move-command-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!