0

I tried using the mv command in my terminal on my mac to move files into a directory. The files were moved, however it seems that I made a mistake i in my command and did not use a using a trailing slash at the end of my directory name. So a file was created instead. I ran the command multiple times thinking that I was moving the files into my newly created directory. When I tried to CD to the directory, my terminal gave me a notice saying "XX" is not a directory. I then tried to open the file and it gave me an error.

  1. What happened to the several files that I moved to this new "XX" file. The files types were word docs (.docx) and excel (.xlsx) documents. Were they combined somehow?

  2. What kind of file did the new "XX" file become? I can't even open this file in any program as it says that it is corrupt.

  3. When using the MV command, is there any possible way to recover the mv's files? I didn't use the rm command.

Sorry, I am new at this.

1 Answer 1

1

You don't need a trailing / when moving files - you need to move multiple files to a directory that already exists. (ie mkdir -p /usr/share/foo/bar && mv /opt/foo/* /usr/share/foo/bar).

That said, your file-not-a-directory is whatever file moved last. If OS X has it, I'd use the file utility to try and determine what type it was, but I think either OS X or a Linux will still recognize it as a file and open with the appropriate application if double-clicked - assuming of course that it is a data file.

You may be able to run strings on it as well and get some (mostly) human readable text info that may be used in various bits of output if it is a binary program.

EDIT - come to think of it, my Linux boxes all warn me about last argument not being a directory if I try to move many to one spot that doesn't exist... What command did you run exactly?

7
  • Ivan, thanks for such a quick reply. The command was mv “filename.docx” Documents/XX
    – Jason
    Commented Aug 12, 2019 at 22:41
  • i ran the command several times mv’ing different files, a total of 4 to be exact, and I got absolutely no warnings. That is what led me to believe that I was in fact moving the files into a directory. When i tried a cd into that directory, it warned me saying that the file was not a directory.
    – Jason
    Commented Aug 12, 2019 at 22:43
  • can you duplicate and confirm using safe/temp/demo files? I just tried on my Linux desktop (no Mac at home) and it warns me and doesn't make any FS changes...
    – ivanivan
    Commented Aug 12, 2019 at 22:46
  • I also thought that the last file I mv’d, if “XX” was not a directory, would simply overwrite the file, but it’s almost like it concatenated the files’ data into one unreadable file. I’m stuck. I’m stupid for not backing up my data, but I need the very first file that I mv’d. I’m running data recover sofware now, since I haven’t saved any new data, i’m hoping that the mv’d files show up.
    – Jason
    Commented Aug 12, 2019 at 22:46
  • One does not need a trailing slash when moving files to a directory, although in the case where the directory does not exist, the use of a trailing slash will cause an error message, rather than the behavior the OP experienced. So while not necessary, it can be helpful.
    – Jim L.
    Commented Aug 12, 2019 at 22:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .