Check whether the USB flash drive is inserted in Linux

Source: Internet
Author: User
In Linux, check whether the USB flash drive is inserted-general Linux technology-Linux technology and application information. The following is a detailed description. 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, to a certain extent and then stored together in the media. If you do not have umount, you will be unable to undo the USB flash drive. The program does not know that fopen, fwrite, and other functions still return correct results. When you know that the operating system needs to write the media, the I/O error is returned. However, a lot of data will be lost due to this untimely Error Report.

In fact, the USB driver modifies the system configuration file when the USB flash drive is inserted and pulled out.

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 not related to 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.