Opening /dev/sdb2
will open the raw block device accessing the partition on the thumb drive, which, if you have a filesystem on the partition, is not at all what you want to do. You need to mount the filesystem first, after which you can access files within it via the mount point. Most linux systems will mount the thumb drive automatically when you plug it in -- if you type mount
at the command line it will show you all the mounted filesystems and where they were mounted. This will probably show you a line like:
/dev/sdb2 on /media/usb type ext2 (...
In which case you open /media/usb/file
to access file
in the root directory of the filesystem on the thumb drive.
If its not mounted automatically, you'll need to mount it manually before accessing it -- you can do that with the mount
program or the mount(2) system call from within a program, but it generally requires superuser permissions.
Regardless of how you mount it, make sure to unmount it before unplugging the thumb drive to make sure that all the data has been written and is up to date.