How to detect USB flash drive is unplugged

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite












On a backup process the program has to copy tar.gz file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec() to run the shell script.
The function itself obtains the stdio.



So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?



The device usually appears as sd[a-z]1 - please note the regex in the string.







share|improve this question


















  • 2




    What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick – is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
    – dessert
    May 16 at 10:38






  • 1




    I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
    – sudodus
    May 16 at 11:30











  • @sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
    – Hairi
    May 16 at 13:21






  • 1




    What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
    – sudodus
    May 16 at 13:25







  • 2




    Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
    – sudodus
    May 16 at 13:33














up vote
1
down vote

favorite












On a backup process the program has to copy tar.gz file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec() to run the shell script.
The function itself obtains the stdio.



So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?



The device usually appears as sd[a-z]1 - please note the regex in the string.







share|improve this question


















  • 2




    What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick – is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
    – dessert
    May 16 at 10:38






  • 1




    I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
    – sudodus
    May 16 at 11:30











  • @sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
    – Hairi
    May 16 at 13:21






  • 1




    What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
    – sudodus
    May 16 at 13:25







  • 2




    Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
    – sudodus
    May 16 at 13:33












up vote
1
down vote

favorite









up vote
1
down vote

favorite











On a backup process the program has to copy tar.gz file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec() to run the shell script.
The function itself obtains the stdio.



So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?



The device usually appears as sd[a-z]1 - please note the regex in the string.







share|improve this question














On a backup process the program has to copy tar.gz file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec() to run the shell script.
The function itself obtains the stdio.



So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?



The device usually appears as sd[a-z]1 - please note the regex in the string.









share|improve this question













share|improve this question




share|improve this question








edited May 23 at 19:46









Zanna

47.9k13117227




47.9k13117227










asked May 16 at 9:32









Hairi

1062




1062







  • 2




    What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick – is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
    – dessert
    May 16 at 10:38






  • 1




    I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
    – sudodus
    May 16 at 11:30











  • @sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
    – Hairi
    May 16 at 13:21






  • 1




    What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
    – sudodus
    May 16 at 13:25







  • 2




    Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
    – sudodus
    May 16 at 13:33












  • 2




    What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick – is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
    – dessert
    May 16 at 10:38






  • 1




    I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
    – sudodus
    May 16 at 11:30











  • @sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
    – Hairi
    May 16 at 13:21






  • 1




    What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
    – sudodus
    May 16 at 13:25







  • 2




    Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
    – sudodus
    May 16 at 13:33







2




2




What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick – is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
– dessert
May 16 at 10:38




What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick – is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
– dessert
May 16 at 10:38




1




1




I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
– sudodus
May 16 at 11:30





I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
– sudodus
May 16 at 11:30













@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
– Hairi
May 16 at 13:21




@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
– Hairi
May 16 at 13:21




1




1




What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
– sudodus
May 16 at 13:25





What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
– sudodus
May 16 at 13:25





2




2




Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
– sudodus
May 16 at 13:33




Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
– sudodus
May 16 at 13:33










3 Answers
3






active

oldest

votes

















up vote
0
down vote













I suggest



lsusb


according to its author,




lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.




An example:



hani@My-FRIEND:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 8087:07dc Intel Corp.
Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).






share|improve this answer





























    up vote
    0
    down vote













    To check which USB disks are connected look in /dev/disk/by-path/



    ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort


    The output of previous command will list only usb disks.



    grep -v "part" - excludes the partitions.



    sdb
    sdc


    Then lsblk command can print some useful info like model and size.




    #!/bin/bash
    for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
    do
    lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
    done




    To check where the partitions of USB disks are mounted




    #!/bin/bash
    for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
    do
    findmnt -rno TARGET /dev/$usbp
    done





    share|improve this answer





























      up vote
      0
      down vote













      I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/ folder.



      When I plugged in my pen drive, I get file /dev/sdc. If I unplugged it then /dev/sdc vanishes .



      Here is some more info about How to check if a file exists in a shell script






      share|improve this answer






















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "89"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );








         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036866%2fhow-to-detect-usb-flash-drive-is-unplugged%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote













        I suggest



        lsusb


        according to its author,




        lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.




        An example:



        hani@My-FRIEND:~$ lsusb
        Bus 001 Device 002: ID 8087:8001 Intel Corp.
        Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
        Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
        Bus 002 Device 005: ID 8087:07dc Intel Corp.
        Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
        Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
        Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
        Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
        Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
        Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


        So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).






        share|improve this answer


























          up vote
          0
          down vote













          I suggest



          lsusb


          according to its author,




          lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.




          An example:



          hani@My-FRIEND:~$ lsusb
          Bus 001 Device 002: ID 8087:8001 Intel Corp.
          Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
          Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
          Bus 002 Device 005: ID 8087:07dc Intel Corp.
          Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
          Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
          Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
          Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
          Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
          Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


          So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).






          share|improve this answer
























            up vote
            0
            down vote










            up vote
            0
            down vote









            I suggest



            lsusb


            according to its author,




            lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.




            An example:



            hani@My-FRIEND:~$ lsusb
            Bus 001 Device 002: ID 8087:8001 Intel Corp.
            Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
            Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
            Bus 002 Device 005: ID 8087:07dc Intel Corp.
            Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
            Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
            Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
            Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
            Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
            Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


            So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).






            share|improve this answer














            I suggest



            lsusb


            according to its author,




            lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.




            An example:



            hani@My-FRIEND:~$ lsusb
            Bus 001 Device 002: ID 8087:8001 Intel Corp.
            Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
            Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
            Bus 002 Device 005: ID 8087:07dc Intel Corp.
            Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
            Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
            Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
            Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
            Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
            Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


            So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 23 at 19:47









            Zanna

            47.9k13117227




            47.9k13117227










            answered May 17 at 7:15









            singrium

            614113




            614113






















                up vote
                0
                down vote













                To check which USB disks are connected look in /dev/disk/by-path/



                ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort


                The output of previous command will list only usb disks.



                grep -v "part" - excludes the partitions.



                sdb
                sdc


                Then lsblk command can print some useful info like model and size.




                #!/bin/bash
                for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                do
                lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
                done




                To check where the partitions of USB disks are mounted




                #!/bin/bash
                for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                do
                findmnt -rno TARGET /dev/$usbp
                done





                share|improve this answer


























                  up vote
                  0
                  down vote













                  To check which USB disks are connected look in /dev/disk/by-path/



                  ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort


                  The output of previous command will list only usb disks.



                  grep -v "part" - excludes the partitions.



                  sdb
                  sdc


                  Then lsblk command can print some useful info like model and size.




                  #!/bin/bash
                  for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                  do
                  lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
                  done




                  To check where the partitions of USB disks are mounted




                  #!/bin/bash
                  for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                  do
                  findmnt -rno TARGET /dev/$usbp
                  done





                  share|improve this answer
























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    To check which USB disks are connected look in /dev/disk/by-path/



                    ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort


                    The output of previous command will list only usb disks.



                    grep -v "part" - excludes the partitions.



                    sdb
                    sdc


                    Then lsblk command can print some useful info like model and size.




                    #!/bin/bash
                    for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                    do
                    lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
                    done




                    To check where the partitions of USB disks are mounted




                    #!/bin/bash
                    for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                    do
                    findmnt -rno TARGET /dev/$usbp
                    done





                    share|improve this answer














                    To check which USB disks are connected look in /dev/disk/by-path/



                    ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort


                    The output of previous command will list only usb disks.



                    grep -v "part" - excludes the partitions.



                    sdb
                    sdc


                    Then lsblk command can print some useful info like model and size.




                    #!/bin/bash
                    for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                    do
                    lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
                    done




                    To check where the partitions of USB disks are mounted




                    #!/bin/bash
                    for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
                    do
                    findmnt -rno TARGET /dev/$usbp
                    done






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 23 at 19:48









                    Zanna

                    47.9k13117227




                    47.9k13117227










                    answered May 17 at 7:01







                    user829010



























                        up vote
                        0
                        down vote













                        I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/ folder.



                        When I plugged in my pen drive, I get file /dev/sdc. If I unplugged it then /dev/sdc vanishes .



                        Here is some more info about How to check if a file exists in a shell script






                        share|improve this answer


























                          up vote
                          0
                          down vote













                          I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/ folder.



                          When I plugged in my pen drive, I get file /dev/sdc. If I unplugged it then /dev/sdc vanishes .



                          Here is some more info about How to check if a file exists in a shell script






                          share|improve this answer
























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/ folder.



                            When I plugged in my pen drive, I get file /dev/sdc. If I unplugged it then /dev/sdc vanishes .



                            Here is some more info about How to check if a file exists in a shell script






                            share|improve this answer














                            I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/ folder.



                            When I plugged in my pen drive, I get file /dev/sdc. If I unplugged it then /dev/sdc vanishes .



                            Here is some more info about How to check if a file exists in a shell script







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited May 23 at 19:50









                            Zanna

                            47.9k13117227




                            47.9k13117227










                            answered May 16 at 9:56









                            noone

                            844420




                            844420






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036866%2fhow-to-detect-usb-flash-drive-is-unplugged%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                pylint3 and pip3 broken

                                Missing snmpget and snmpwalk

                                How to enroll fingerprints to Ubuntu 17.10 with VFS491