bash script problem, find , mv tilde files created by gedit

喜欢而已 提交于 2019-12-08 11:54:01

问题


im using linux with gedit which has the wonderful habit of creating a temp file with a tilde at the end for every file I edit.

im trying to move all of these files at once to a different folder using the following:

find . -iname “*.php~” -exec mv {} /mydir \;

However, its now giving me syntax errors, as if it were searching through each file and trying to move the piece of text. I just want to move all of the files ending in .php~ to another directory. Any idea how I do that?

Cheers Ke


回答1:


Try this one-liner:

for D in `find . -iname "*.php~"`; do mv ${D} /mydir; done

For future reference, if you go into Edit > Preferences > Editor Tab, there is checkbox for "Create a backup copy of files before saving" That is the guy responsible for creating the tilde version.




回答2:


GNU find

find . -iname "*.php~" -exec mv "{}" /mydir +;

or

for file in *.php~
do
 echo mv "$file" /mydir
done


来源:https://stackoverflow.com/questions/2640260/bash-script-problem-find-mv-tilde-files-created-by-gedit

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