PDA

View Full Version : UNIX mv command mistake


cepheid
Jul21-09, 12:50 PM
Hi,

I was trying to type:

mv *.txt some_other_directory

but I accidentally hit 'return' after just typing:

mv *

Many of the .txt files in my current directory disappeared (but not all of them, strangely enough). Does anyone know what might have happened to them and how to undo the mistake?

mgb_phys
Jul21-09, 12:59 PM
The * is expanded by the shell into a list of files
So the mv command sees

mv a.txt b.txt c.txt d.txt e.txt
It then moves all the files to the last one if the last match is a directory, otherwise it should fail (at least on linux)

Hurkyl
Jul21-09, 05:14 PM
how to undo the mistake?
Backups. Maybe you have copies of the files lying about in other places.

harborsparrow
Jul29-09, 07:24 PM
the lesson? never mv. cp and then del

Hurkyl
Jul29-09, 07:58 PM
Or alias mv so that it prompts before overwriting anything.