LinuxQuestions.org
Help answer threads with 0 replies.
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


Closed Thread
  Search this Thread
Old 10-30-2009, 12:50 AM   #1
whatis
LQ Newbie
 
Registered: Oct 2009
Posts: 12

Rep: Reputation: 0
Traversing /dev


Hi

I am new to the Linux platform.

How can I write a program that traverses /dev and prints the major and minor numbers for the devices
 
Old 10-30-2009, 07:22 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
In C, you would use opendir and readdir to traverse the directories, and stat to examine the file details. The stat call will give (amongst other things) the device id st_rdev, and you can extract the device numbers from this using the major and minor macros which are found in 'sys/sysmacros.h' (which is included by 'sys/types.h').

Last edited by neonsignal; 10-30-2009 at 07:25 AM.
 
Old 10-30-2009, 10:09 AM   #3
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,665

Rep: Reputation: 485Reputation: 485Reputation: 485Reputation: 485Reputation: 485
A respectable reply. Thanks neonsignal.
 
Old 10-30-2009, 10:13 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place.

Because there are posts in both threads, I'll get this one merged into the other
 
Old 10-31-2009, 09:02 AM   #5
whatis
LQ Newbie
 
Registered: Oct 2009
Posts: 12

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks Alot!!

That was great help!
 
Old 11-01-2009, 06:45 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Closed in favour of the more sensibly placed dupe.

http://www.linuxquestions.org/questi...ng-dev-765489/
 
  


Closed Thread

Tags
dev, minor


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
Traversing Subnets gankoji Linux - Networking 6 10-24-2009 01:14 AM
traversing in parsed xml document naveenisback Programming 1 07-16-2009 08:59 AM
C Shell - Traversing a file lundq1kp Linux - Newbie 1 06-06-2008 06:41 PM
Recursively traversing sub-directories ark86 Linux - Newbie 2 01-29-2006 01:15 PM
Traversing from previous post c0rk3y *BSD 1 07-26-2002 09:15 PM

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

All times are GMT -5. The time now is 08:50 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration