0

I accidentally did

  • mv file /an/important/directory

instead of

  • mv file /an/important/directory/ or
  • mv file -t /an/important/directory,

so it now looks like /an/important/directory/ is clobbered. (I thought I† aliased mv to mv -i to prevent this kind of thing…)

But my filesystem is not smaller, making me think the files have not actually moved and I could do something to an inode to help the system find and organise those non-deleted files again.


Added: since same drive is apparently important, I should add that /media/target.folder is what I clobbered. I was trying to move stuff off /dev/sda1.


sudo mv: oh wait. I didn't alias mv=mv -i in /home/root/.bash_aliases as well as in ~/.bash_aliases. sudo mv likely calls the root version. Whoops.


UPDATE: Per @HackSlash’s comment, here is what my /media directory looks like:

i@scheherezade:/media$ ls -oh
total 80K
drwxr-xr-x   4 root 4.0K Jul 26 16:17 backup
drwxr-xr-x   2 root 4.0K Dec  8  2016 DEIMOS
drwxrwxrwx  69 mars 4.0K Mar 14 13:20 PHOBOS
drwxr-xr-x 113 i     56K Jul 26 18:10 media
drwxr-xr-x   4 root 4.0K Mar 31 08:43 opt
drwxrwxr-x   7 i    4.0K Mar 30 17:27 puck

I was trying to move file to /media/media, where the first /media is the system saying "things that are mounted", and the second /.../media is me saying "video and audio files". Something is clearly different about /media/media, but I don’t know if this answers @HackSlash’s suggestion about symlinks.

isomorphismes
  • 1,864
  • 2
  • 20
  • 31
  • 1
    mv won't clobber a directory that easily. You just moved the file into it. –  Jul 26 '17 at 21:16
  • @WumpusQ.Wumbley When I did `ls -oh /an/important/`, it showed that the directory had become the renamed file. – isomorphismes Jul 26 '17 at 21:26
  • @WumpusQ.Wumbley Also, `ls -oh/an/important/directory` now does not contain anything. – isomorphismes Jul 26 '17 at 21:27
  • Wumpus is correct: `Note: mv will only replace empty directories in the destination. Conflicting populated directories are skipped with a diagnostic. ` https://www.gnu.org/software/coreutils/manual/html_node/mv-invocation.html – HackSlash Jul 26 '17 at 22:31
  • You likely have a typo somewhere – HackSlash Jul 26 '17 at 22:31
  • 2
    OR: Was that directory a symlink or softlink? – HackSlash Jul 26 '17 at 22:32
  • @HackSlash even in that case the file is moved to it and doesn't overwrite the link. – xenoid Jul 27 '17 at 08:13
  • @HackSlash what kind of typo do you mean? – isomorphismes Jul 31 '17 at 16:35
  • @HackSlash Yes, it may have been, because it's in `/media`, which I think is controlled by symlinks – isomorphismes Jul 31 '17 at 16:35
  • If it's a mount point then the files could be under the mount point. If they aren't in the physical location that is mounted then that is what I would check next. Unmount the media and then look at the location again. You will see that the contents has changed. – HackSlash Aug 01 '17 at 18:54

1 Answers1

0

What happened was: I had tried to mv /some/file /media/backup without mount /dev/sd1 /media/backup really being mounted. (When I close my laptop, network and USB hard drives disconnect.) So files were actually being copied to /dev/sda1 's root / tree, one layer down in a folder called /media. (I had to back up with sudo anyway, so the user-vs-root protection didn't stop me.) In turn, files in /media/backup (which was really /dev/sda1) were not behaving like the connected peripheral device I thought they were.

I used lsblk -f to see which things really were mounted, and where. (You can also use df -h /media/backup/ to see which UUID a folder is on. ( cat /proc/*some*file*I*forget*which* shows this information too.)

lsblk -f also tells me the names of the hardware volumes, which I've chosen to match the names of the mount points under /media/*/. To prevent confusion between the old putative /media/*/ mounts and the new correct mounts, I mounted /dev/sdk1 etc to /mnt/sdk1/.

Then mv behaves as expected.


This is on Ubuntu.

isomorphismes
  • 1,864
  • 2
  • 20
  • 31