0

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

Ke.
  • 2,484
  • 8
  • 40
  • 78

2 Answers2

2

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.

Mike Clark
  • 11,769
  • 6
  • 39
  • 43
  • cool, thanks for this, is there any way I can preserve the file structure of those files? its asking me to replace. Also im sure i used to be able to view these hidden files in nautilus but for some reason its not showing them anymore, would love to find out how to show them , thx again :) – Ke. Apr 14 '10 at 19:17
  • Sorry, off the top of my head I am not sure the way to preserve the structure. – Mike Clark Apr 14 '10 at 19:38
  • you can just use `find` with `-exec`. Moreover this will fail on files with spaces. – ghostdog74 Apr 14 '10 at 23:42
0

GNU find

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

or

for file in *.php~
do
 echo mv "$file" /mydir
done
ghostdog74
  • 327,991
  • 56
  • 259
  • 343