Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

UNIX mv command mistake

  1. Jul 21, 2009 #1

    cepheid

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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?
     
  2. jcsd
  3. Jul 21, 2009 #2

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    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: Jul 21, 2009
  4. Jul 21, 2009 #3

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Backups. Maybe you have copies of the files lying about in other places.
     
  5. Jul 29, 2009 #4

    harborsparrow

    User Avatar
    Gold Member

    the lesson? never mv. cp and then del
     
  6. Jul 29, 2009 #5

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Or alias mv so that it prompts before overwriting anything.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: UNIX mv command mistake
  1. Unix question (Replies: 9)

  2. Printers on UNIX (Replies: 2)

  3. Running UNIX (Replies: 4)

Loading...