Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How do i find a file major and minor number

by mmw (Initiate)
on Dec 07, 2011 at 17:41 UTC ( #942294=perlquestion: print w/ replies, xml ) Need Help??
mmw has asked for the wisdom of the Perl Monks concerning the following question:

How do i retrieve the major and minor number using File::stat?
#!/usr/bin/perl use File::Find; find sub { (-c | -b ) && push(@files,$File::Find::name) } , ("/dev") ; sub retHash () { my ($name, $major, $minor ) = split(",",stat -c '%n,%t,%T' $_`); my $return = {name=> $name, major=> hex($major), minor=> hex($minor +) }; return $return; } @files = map ( &retHash($_) , @files); foreach $item (@files) { print "$item->{name} $item->{major} $item->{minor}\n"; }

Comment on How do i find a file major and minor number
Download Code
Re: How do i find a file major and minor number
by johngg (Abbot) on Dec 07, 2011 at 17:55 UTC

    Probably something similar to this using lstat or stat.

    knoppix@Microknoppix:~$ perl -E ' > $rdev = ( stat q{/dev/zero} )[ 6 ]; > $minor = $rdev % 256; > $major = int( $rdev / 256 ); > say $rdev; > say $major; > say $minor;' 261 1 5 knoppix@Microknoppix:~$ ls -l /dev/zero crw-rw-rw- 1 root root 1, 5 Dec 7 11:39 /dev/zero knoppix@Microknoppix:~$ perl -E ' > $rdev = ( stat q{/dev/zram0} )[ 6 ]; > $minor = $rdev % 256; > $major = int( $rdev / 256 ); > say $rdev; > say $major; > say $minor;' 64512 252 0 knoppix@Microknoppix:~$ ls -l /dev/zram0 brw-rw---- 1 root disk 252, 0 Dec 7 11:39 /dev/zram0 knoppix@Microknoppix:~$

    I hope this is helpful.

    Cheers,

    JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://942294]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-10-01 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (29 votes), past polls