How to check whether a USB flash disk is connected in Linux

Source: Internet
Author: User
The Linux file system is asynchronous. that is to say, writing a file is not saved to the media (hard disk, USB flash disk, etc.) immediately, but saved to the buffer zone, and save them to the media together to a certain extent, such

The Linux file system is asynchronous. that is to say, writing a file is not saved to the media (hard disk, USB flash disk, etc.) immediately, but saved to the buffer zone, after accumulating data to a certain extent and then saving it to the media, if there is no umount, the USB flash drive will be illegally pulled out, and the program will not know. fopen, fwrite, and other functions will still return correct results, i/O errors are reported only when the operating system writes the media. However, many data is lost due to this untimely error report.

In fact, the USB driver modifies the system configuration file during USB flash drive insertion and removal.

For example, the USB flash drive records Attached: Yes or No in/proc/scsi/usb-storage-0/0 during insertion or removal.

By checking this file, it is not difficult to check whether the USB flash drive is inserted or unplugged.

Note:Whether the USB flash drive is inserted is independent of whether it is mounted.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.