How to Detect the Presence of USB Flash Drive in Linux bash script?

Posted on 2011-05-01
Last Modified: 2012-05-11

I'm using Linux Fedora 14 Distro.

I need to detect the presence of a USB flash drive in a bash script and then make one of two choices based on whether it's there or not.

How can I do this?  Specific code is greatly appreciated.

Question by:SqueezeOJ
    LVL 3

    Accepted Solution


    Author Comment

    Thanks Abhishek_Chib!

    Here's the code I generated from that link:

    if sudo lshw | grep "label=MyUSBDrive" ; then
      echo "Flash Drive Available"
      echo "Flash Drive NOT Available"

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now