What happened to my .txt files after accidentally using 'mv *' in UNIX?

  • Thread starter Thread starter cepheid
  • Start date Start date
  • Tags Tags
    Mistake Unix
Click For Summary

Discussion Overview

The discussion revolves around the consequences of using the 'mv *' command in a UNIX environment, particularly focusing on the disappearance of .txt files and potential recovery methods. The scope includes practical advice, command behavior, and user experiences related to file management in UNIX.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes that the '*' wildcard is expanded by the shell, which leads to the mv command attempting to move all files in the directory, potentially resulting in unexpected behavior if the last item is a directory.
  • Another participant suggests that the only way to undo the mistake is through backups, implying that recovery may depend on prior file management practices.
  • A different viewpoint emphasizes a lesson learned from the incident, advocating for using 'cp' instead of 'mv' to avoid loss of files.
  • One participant proposes creating an alias for the mv command that prompts the user before overwriting files, suggesting a preventive measure for future use.

Areas of Agreement / Disagreement

Participants express various opinions on the best practices for file management in UNIX, with no consensus on a single solution or method for recovery. The discussion includes both technical explanations and personal recommendations, indicating a range of perspectives on the issue.

Contextual Notes

There is an implicit assumption that users have varying levels of familiarity with UNIX commands and file management practices. The discussion does not resolve the specific outcomes of the mv command in this context, nor does it clarify the exact state of the missing files.

cepheid
Staff Emeritus
Science Advisor
Gold Member
Messages
5,197
Reaction score
38
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?
 
Computer science news on Phys.org
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)
 
Last edited:
cepheid said:
how to undo the mistake?
Backups. Maybe you have copies of the files lying about in other places.
 
the lesson? never mv. cp and then del
 
Or alias mv so that it prompts before overwriting anything.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 35 ·
2
Replies
35
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 6 ·
Replies
6
Views
8K
Replies
29
Views
5K