Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 02-01-2007, 12:41 AM   #1
LQ Newbie
Registered: Dec 2004
Posts: 1

Rep: Reputation: 0
How to detect programatically if a USB device is is plugged-in / plugged out?

Hi all,

How can I programatically detect if any USB drive (say thump drive) is plugged-in or plugged out at any time?
Also get details on the device plugged-in?
Can I use udev rules to achieve this?
The goal is to get access to the contents within the program.

Thanks for your help.
Old 02-01-2007, 01:19 AM   #2
Registered: Dec 2005
Location: South Africa
Distribution: CentOS,Ubuntu,Fedora
Posts: 249

Rep: Reputation: 30

I suppose you could use the "lsusb" command, which then references to the /dev/sd... device.

Old 02-01-2007, 03:49 AM   #3
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,057

Rep: Reputation: 377Reputation: 377Reputation: 377Reputation: 377
I think you can do this with udev rules. See this link:
Old 02-01-2007, 04:01 AM   #4
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
Both method would work.
As you are using udev, you always know what will be the name of the device node in /dev.
Then this is ok (for shell scripts) :
[ -b /dev/sda ] && echo "sda present" || echo "sda not present"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help mounting USB flash drive ... When plugged in I dont have /dev/sda1 device ... ebenh Ubuntu 2 09-17-2006 09:55 PM
usb device works only when is plugged in after booting Jaa Linux - Hardware 2 08-22-2006 10:00 AM
how to know a usb device is plugged in/out lordofring Linux - Software 2 04-25-2005 01:15 PM
Why does PC hang when USB device is plugged in? DeepSPiN Fedora 1 12-03-2003 10:59 AM
System freezes during boot with USB device plugged in. dhrivnak Slackware 3 10-31-2003 08:55 PM

All times are GMT -5. The time now is 12:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration