Linux SoftwareProgrammingLibrariesStat::lsMode 0.50

Stat::lsMode 0.50


Stat::lsMode Perl module can format file modes like the ls -l command does. SYNOPSIS use Stat::lsMode; $mode = (stat $fi
Developer:   Dmitry Fedorov
      more software by author →
Price:  0.00
License:   Perl Artistic License
File size:   3K
Language:   
OS:   
Rating:   0 /5 (0 votes)
Your vote:  
enlarge screenshot


Stat::lsMode Perl module can format file modes like the ls -l command does.

SYNOPSIS

use Stat::lsMode;

$mode = (stat $file)[2];
$permissions = format_mode($mode);
# $permissions is now something like `drwxr-xr-x'

$permissions = file_mode($file); # Same as above

$permissions = format_perms(0644); # Produces just 'rw-r--r--'

$permissions = format_perms(644); # This generates a warning message:
# mode 644 is very surprising. Perhaps you meant 0644...

Stat::lsMode->novice(0); # Disable warning messages

Stat::lsMode generates mode and permission strings that look like the ones generated by the Unix ls -l command. For example, a regular file that is readable by everyone and writable only by its owner has the mode string -rw-r--r--. Stat::lsMode will either examine the file and produce the right mode string for you, or you can pass it the mode that you get back from Perl's stat call.

format_mode

Given a mode number (such as the third element of the list returned by stat), return the appopriate ten-character mode string as it would have been generated by ls -l. For example, consider a directory that is readable and searchable by everyone, and also writable by its owner. Such a directory will have mode 040755. When passed this value, format_mode will return the string drwxr-xr-x.
If format_mode is passed a permission number like 0755, it will return a nine-character string insted, with no leading character to say what the file type is. For example, format_mode(0755) will return just rwxr-xr-x, without the leading d.

file_mode

Given a filename, do lstat on the file to determine the mode, and return the mode, formatted as above.

Novice Operation Mode

A common mistake when dealing with permission modes is to use 644 where you meant to use 0644. Every permission has a numeric representation, but the representation only makes sense when you write the number in octal. The decimal number 644 corresponds to a permission setting, but not the one you think. If you write it in octal you get 01204, which corresponds to the unlikely permissions -w----r-T, not to rw-r--r--.

The appearance of the bizarre permission -w----r-T in a program is almost a sure sign that someone used 644 when they meant to use 0644. By default, this module will detect the use of such unlikely permissions and issue a warning if you try to format them. To disable these warnings, use

Stat::lsMode->novice(0); # disable novice mode

Stat::lsMode->novice(1); # enable novice mode again

The surprising permissions that are diagnosed by this mode are:

111 => --xr-xrwx
400 => rw--w----
440 => rw-rwx---
444 => rw-rwxr--
551 => ---r--rwt
600 => --x-wx--T
640 => -w------T
644 => -w----r-T
660 => -w--w-r-T
664 => -w--wx--T
666 => -w--wx-wT
700 => -w-rwxr-T
711 => -wx---rwt
750 => -wxr-xrwT
751 => -wxr-xrwt
751 => -wxr-xrwt
755 => -wxrw--wt
770 => r------wT
771 => r------wt
775 => r-----rwt
777 => r----x--t

Of these, only 400 is remotely plausible.

BUGS

As far as I know, the precise definition of the mode bits is portable between varieties of Unix. The module should, however, examine stat.h or use some other method to find out if there are any local variations, because Unix being Unix, someone somewhere probably does it differently.

Maybe it file_mode should have an option that says that if the file is a symlink, to format the mode of the pointed to file instead of the mode of the link itself, the way ls -Ll does.

Requirements:
  • Perl
    tags the mode  stat lsmode  format mode  the file  lsmode novice  will return  return the  for example  mode string  permissions format  file mode  wxr xrwt  unlikely permissions  

    Download Stat::lsMode 0.50


     http://mirrors.evolva.ro/CPAN/authors/id/M/MJ/MJD/Stat-lsMode-0.50.tar.gz


    Authors software

    offmirror 1.3 (by Dmitry Fedorov)
    offmirror is a utility for mirroring a tree of files

    File::Stat::Bits 1.00 (by Dmitry Fedorov)
    File::Stat::Bits - stat bit mask constants.

    SYNOPSIS:

    use File::stat;
    use File::Stat::Bits;

    my $st = stat($f

    File::Stat::ModeString 1.00 (by Dmitry Fedorov)
    File::Stat::ModeString - conversion file stat mode to/from string representation.

    SYNOPSIS

    use File::Stat::ModeString;

    $st

    Stat::lsMode 0.50 (by Dmitry Fedorov)
    Stat::lsMode Perl module can format file modes like the ls -l command does.

    SYNOPSIS

    use Stat::lsMode;

    $mode = (stat $fi


    Similar software

    Stat::lsMode 0.50 (by Dmitry Fedorov)
    Stat::lsMode Perl module can format file modes like the ls -l command does.

    SYNOPSIS

    use Stat::lsMode;

    $mode = (stat $fi

    File::Stat::ModeString 1.00 (by Dmitry Fedorov)
    File::Stat::ModeString - conversion file stat mode to/from string representation.

    SYNOPSIS

    use File::Stat::ModeString;

    $st

    File::Stat::Bits 1.00 (by Dmitry Fedorov)
    File::Stat::Bits - stat bit mask constants.

    SYNOPSIS:

    use File::stat;
    use File::Stat::Bits;

    my $st = stat($f

    mode.pl 1.1-051212 (by Marcus Liback)

    Convert::UU 0.52 (by Andreas Koenig)
    Convert::UU is a Perl module for uuencode and uudecode.

    SYNOPSIS

    use Convert::UU qw(uudecode uuencode);
    $encoded_string =

    Chart::EPS_graph::Test 0.01d (by Gan Uesli Starling)
    SYNOPSIS

    From the CLI, call as below where '/some/dir/' is any directory you have permission to write to.

    perl -e "use Chart::E

    Filer 0.0.12 (by Jens Luedicke)

    athcool 0.3.11 (by Osamu Kayasono)
    athcool is a small utility, enabling/disabling Powersaving mode for AMD Athlon/Duron processors.

    Since enabling Powersaving mode,

    C# for Emacs 0.4.0 (by D. Moonfire)
    C# for Emacs is a derived mode implementing most of the C# rules.

    After a good number of years, we noticed that there wasn't a "no

    Archive::Ar 1.13b (by Jay Bonci)
    Archive::Ar is a Perl interface for manipulating ar archives.

    SYNOPSIS

    use Archive::Ar;

    my $ar = new Archive


    Other software in this category

    zlib 1.2.3 (by Jean-loup Gailly)
    zlib is designed to be a free, general-purpose, legally unencumbered, lossless data-compression library for use on virtually any comp

    libjpeg v6b (by Independent JPEG Group)
    libjpeg is a library for handling the JPEG (JFIF) image format

    OpenSSL 0.9.7c (by The OpenSSL Project Team)
    The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implement

    libxml2 2.6.27 (by DV)
    Libxml2 is the XML C parser and toolkit developed for the Gnome project (but usable outside of the Gnome platform), libxml2 library i

    GNU C library 2.4 (by Andreas Jaeger)
    GNU C library (glibc) is one of the most important components of GNU Hurd and most modern Linux distributions.

    GNU C library is us

  •     search


    Featured Software

    jEdit 4.3 pre8
    jEdit is an Open Source text editor written in Java

    Opera 9.02
    Surf the Internet in a safer, faster, and easier way with Opera browser

    GNU Aspell 0.60.4
    GNU Aspell is a Free and Open Source spell checker designed to eventually replace Ispell


    Subscribe in Rojo
    Google Reader
    Add to My Yahoo!

    Add to My AOL
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    Add 'nixbit linux software' to Newsburst from CNET News.com
    del.icio.us nixbit linux software


    Top tags