LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-29-2013, 02:04 AM   #1
abhijeetsn
LQ Newbie
 
Registered: Jul 2013
Posts: 2

Rep: Reputation: Disabled
listing the filesystem on usb stick


Hi
i am very new to shell scripting and i am stuck at the following problem
1. Write a script to list the USB devices mounted on a Linux system?
a. And the script should list of files stored on the USB stick


I am using command "ls -l /dev/disk/by-id/usb*" to find usb mounted on system but not able to access the files on usb stick
Any help is appreciated.
Thanks
 
Old 07-29-2013, 03:39 AM   #2
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
You are using the path to the device in /dev, which doesn't work to list files. You should use the path to the mountpoint. You could find out the mountpount by reading it from the output of

Code:
mount
without any arguments.
 
Old 07-30-2013, 06:22 AM   #3
abhijeetsn
LQ Newbie
 
Registered: Jul 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks joe 2000
but in mount command no usb device is showing but in above ls command 3 are showing. can you just tell me how to find those.
 
Old 07-30-2013, 07:46 AM   #4
dt64
Member
 
Registered: Sep 2012
Distribution: RHEL5/6, CentOS5/6
Posts: 218

Rep: Reputation: 38
If there is no USB listed in mount output my first guess would be that your USB devices aren't mounted. Mount them and try again.
 
Old 07-30-2013, 07:51 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by abhijeetsn View Post
Write a script to list the USB devices mounted on a Linux system?

I am using command "ls -l /dev/disk/by-id/usb*" to find usb mounted on system
The entries in /dev/disk/by-id/usb* do not reflect if they are mounted. These entries show the device, the available partitions on them (if any) and the /dev/xyz entries they can be reached at.

A lot of distro's use automount and this might give the impression that you are looking at mounted entries, which is not the case.

You need to check the ../../sdXY entries shown in /dev/disk/by-id/usb* to the /dev/sdXY entries shown in the output of the mount command to make sure they are actually mounted.

Code:
lrwxrwxrwx 1 root root    9 jul 30 14:26 usb-KDT_410_001A92053B6ABAA0813400B2-0:0 -> ../../sdf
lrwxrwxrwx 1 root root   10 jul 30 14:26 usb-KDT_410_001A92053B6ABAA0813400B2-0:0-part1 -> ../../sdf1
The red entry is the device itself and not of any interest in this case. The green part is.
Code:
mount | grep sdf1
/dev/sdf1 on /mnt type ext3 (rw)
If the above command shows an entry then it is mounted. This also shows you its mountpoint (the blue part), which can be used to list what is on it.

Up to you to try to accomplish this. We are willing to help if you get stuck, but won't do the assignment for you.

Last edited by druuna; 07-30-2013 at 07:53 AM.
 
Old 07-30-2013, 02:51 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,984

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
I might combine outputs from lsusb and mount then mount if not alread then use them into a way to ls.
 
  


Reply



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
Hauppauge wintv-hvr h006 - dvb-t tuner - usb-stick - hybrid tv stick Xeratul Linux - Hardware 5 12-23-2012 09:47 AM
mount does not detect a vfat filesystem in my usb stick ernesto_cgf Linux - Hardware 3 12-07-2005 07:19 AM
mount/umount usb stick - PQI Intelligent Stick 2.0 sandbag Linux - Software 5 05-06-2005 11:12 AM
USB stick, "losing space" - filesystem inconsistensies? iskrem Linux - Hardware 1 11-26-2004 06:01 PM
Philips Key008 USB camera/memory stick filesystem problem Iskendar Linux - Hardware 0 07-13-2004 08:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:08 PM.

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