13

I downloaded a short video, then wrote:

sudo mv /home/myname/Downloads/m.mp4 /dev/sdb1 

the video disappeared completely. It's not in the USB drive. I searched for it by writing:

find / m.mp4 
find m.mp4 

But it's nowhere to be found.I keep getting

find: ‘m.mp4’: No such file or directory

The USB is mounted and accessible. The video is no longer in Downloads.

Sudodus, thank you. I still don't get it fully but I understand I should've used the mount point. I used it and it worked, like magic. Nothing was erased from the USB, so I am not sure why you apologized. How would you know what the mount point is? I found it in Gparted. And what does this mean, from Gparted:

init :: non DOS media
Cannot initialize '::'
mlabel: Cannot initialize drive

init :: non DOS media
Cannot initialize '::'

The output when I wrote sudo ls -l /dev/sdb1 is

-rw-rw-r-- 1 moe moe 23362068 Jul  2 15:44 /dev/sdb1
  • Next time remember that /dev/sdb1 should be mounted, not treated as a way to put files on the device. However Ubuntu and most other distros will mount things for you automatically, e.g. at /media/<username>/xyz – Artelius Jul 2 at 22:56
  • As an aside, your find command is incorrect; it should be find / -iname 'm.mp4'. Also using file /dev/sdb1 would show that it is a MP4 file, not a special device. – CSM Jul 4 at 17:02
30

Your file is still there. It's just now named /dev/sdb1 and has replaced the device special node that would otherwise be used to mount your USB disk.

You can recover it by moving it back to somewhere else, for example:

sudo mv /dev/sdb1 /home/myname/Downloads/m.mp4

Don't overwrite files in /dev as these are not normal files, but special markers which give the OS raw access to certain hardware devices. Your use of sudo mv destroyed the device special node /dev/sdb1 and replaced it with your video file.

After you move the video back to where it came from, eject and reinsert your USB stick, and you can write files to it via its mount point (typically /run/media/yourusername/USBSTICKNAME but you can run the command mount to see where it was actually mounted). Linux will recreate the device special /dev/sdb1 if necessary when you reinsert the USB stick.

Also note that if your USB stick was correctly mounted by the system, its files should be writable by your username, and you should not need to use sudo to move files to or from it.

| improve this answer | |
  • 13
    Also if you didn't use sudo then the computer wouldn't have let you do this dumb thing. – user253751 Jul 3 at 10:35
  • 12
    @user253751 I think the use of sudo was due to a failed attempt to move the file to the USB with mv ... /dev/sdb1 (no sudo). It probably gave an error, like, "Permission denied". The general advice would be that any 'mv` that gives a permission denied error is an mv you want to analize before slapping sudo to it. – Ismael Miguel Jul 3 at 17:25
  • 2
    As much as it's not part of what the question is asking, I think it would be really useful for this answer to include a brief reminder that the commands in the post probably should never have been run with sudo. – David Z Jul 4 at 6:20
  • @DavidZ I already said this scenario does not require sudo! – Michael Hampton Jul 4 at 12:36
  • Ah, somehow I missed that part, sorry! Though FWIW I would favor a stronger statement, not just "you shouldn't have to use sudo" but rather "you should not be using sudo" or something along those lines. – David Z Jul 5 at 0:18
4

lsblk command could be used to find out your mount point:

$ lsblk | grep -v loop
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 223.6G  0 disk 
├─sda1   8:1    0     1M  0 part 
├─sda2   8:2    0 221.6G  0 part /
└─sda3   8:3    0     2G  0 part [SWAP]
sdb      8:16   0 232.9G  0 disk 
└─sdb1   8:17   0 232.9G  0 part /home

All devices in /dev/ folder are recreated during OS start. You could see it by ls -ailh /dev/ command and in case if some device have been reattached.

If you'll have a deal with Android device, you could find your device storages in /var/run/user/1000/gvfs folder, where 1000 is uid of your user.

$ ls /var/run/user/1000/gvfs
gvfs/      gvfs-burn/ 
user@ubuntu:~$ cd /var/run/user/1000/gvfs/mtp\:host\=Xiaomi_Redmi_6A_3951d46a7d27/
user@ubuntu:/var/run/user/1000/gvfs/mtp:host=Xiaomi_Redmi_6A_3951d46a7d27$ ls
 disk  'Internal shared storage'
user@ubuntu:/var/run/user/1000/gvfs/mtp:host=Xiaomi_Redmi_6A_3951d46a7d27$ echo $UID
1000

Devices also could be mount automatically into /media/$USER or /mnt folders.

| improve this answer | |
1

It could be because of usb-port. Sometimes usb-ports of computers or notebooks are not fully mounted by driver. So you could try :

umount /dev/sdb1

or

sudo umount /dev/sdb1

then

mount /dev/sdb1

or

sudo mount /dev/sdb1

If this does not help - plug-out and plug-in again the usb-drive (usb-stick?). Then repeat umount and mount again like written above.

When you want to move or to copy files as sudo, then you need to mount as sudo too.

Before you move or copy files not as sudo, instead as normal user - then you can umount or mount as normal user too. It depends on the files, which file-permissions they have.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.