I have seen a lot of stuff on how to get the mount point of a disk drive, such as a usb.
Okay so the thing was that I wanted to copy all the folders in my usb to another folder automatically after the usb is plugged in(without manually operation). If I use C, then I can only copy one file every time and use some loop but not the whole folder so it takes a long time. So i was thinking of using cp command in shell file to achieve the goal. I use sudo fdisk to get the mount point of the usb, like /dev/sda1. But in copy command I need to use a real directory such as /media/*** (not that pseudo directory). So I was wondering how you could use /dev/sda1 in cp command or at least use it to find the real directory of the usb.
ps: I might have a wrong understanding on mount point
Thank you!
1 Answer
The question is somewhat confusing, but I believe you are asking how to find a mount point (e.g. /media/myusb/
) by knowing only device name (e.g. /dev/sda1
). You can do it for example with findmnt
tool:
$ findmnt /dev/sda1
TARGET SOURCE FSTYPE OPTIONS
/media/myusb /dev/sda1 iso9660 ro,relatime
you can also search in other direction with findmnt /media/myusb
or just list all mounted points with findmnt -l
.
It is possible that your system won't have findmnt
, so let me also offer as an alternative lsblk /dev/sda1
. This tool could be even more powerful as it can list partitions which are not mounted at all (for example if you want to check their size) but it works in "one direction" only.
/dev/sda
is the device, not a mount point. The mount point is the directory where you mount the device. Is it mounted automatically ? Where it is mounted will depend on what you use to mount it.