0

While consolidating ebooks, I came across what appeared to be a handy fix for my specific operation; namely, I wanted to move all mobi files from different sub-folders in to one central folder named, imaginatively, 'mobi' ...

   $ find -name '*.mobi' -exec mv {} /mobi \;

And, yes, I did make a back up... exactly one directory above. And only realized what I had done until afterwards. (Originals and backup moved/gone.)

After some searching, I found what appears to be a folder but looks like a .mobi file in my root directory. It's about 1.5mb (from 30 ebooks); opening in Atom gives me gibberish (not code).

I assume this is some sort of dastardly ammalgamation of my previous files, melted grotesquely in to each other like the thing from The Thing.

Is there a way to undo my foolishness?

2
  • 2
    I cannot think of any circumstances under which mv would ever concatenate files. What actually happened depends on whether or not /mobi existed as a directory before the operation and whether there were any pair of source files with the same filenames.
    – Celada
    Feb 12, 2017 at 19:06
  • And to prevent mistakes like these, it's a good idea to (1) always use mv -i (possibly with shell alias), (2) always end directories with a trailing /.
    – dirkt
    Feb 13, 2017 at 9:44

1 Answer 1

7

The command you ran will have executed mv <file> /mobi for each <file> that it found. There are several possible outcomes:

  1. /mobi existed before, as a directory that your user is allowed to write into: then each of your mobi files is now inside directory /mobi (if any two had the same name, one of them will have overwritten the other);

  2. either /mobi existed before as a file your user is allowed to overwrite, or it did not exist but your user is allowed to create files under /: then each of you mobi files will have overwritten, in sequence, the file /mobi, which now has, as its contents, the last of the files that find found;

  3. otherwise, all of the mv commands should have failed, and nothing was moved.

Scenario (2) really only sounds likely if you ran your command as root (which the $ hints against). In that case, all your files except the last one that mv operated on are lost. I can't think of a sensical way that mv would concatenate files.

You must log in to answer this question.

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