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
SUMMARY

The discussion centers on the consequences of using the 'mv *' command in UNIX, which resulted in the unintended movement of .txt files. Participants clarified that the shell expands the '*' wildcard to include all files in the directory, leading to the last file being treated as the destination. The recommended solutions include checking for backups and using 'cp' instead of 'mv' to prevent data loss. Additionally, users are advised to create an alias for 'mv' that prompts for confirmation before executing any file moves.

PREREQUISITES
  • Understanding of UNIX command line operations
  • Familiarity with the 'mv' and 'cp' commands
  • Knowledge of shell wildcard expansion
  • Basic backup strategies for file management
NEXT STEPS
  • Research how to create aliases in UNIX for safer command execution
  • Learn about effective backup solutions for UNIX file systems
  • Explore the implications of shell wildcard usage in command line operations
  • Study the differences between 'mv' and 'cp' commands in UNIX
USEFUL FOR

This discussion is beneficial for UNIX users, system administrators, and anyone involved in file management who seeks to avoid accidental data loss through command line operations.

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