Mauricio Araya V.

Computer engineer, infrastructure specialist and freedom advocate

Follow me on GitHub

Getting file pemissions

21 Mar 2015

I have to admit it, I’m usually a little lazy so I prefer to have a bunch of scripts ready to work for me located at ~/bin. The following Perl scripts is one of them, it has been with me for years now:

#!/usr/bin/env perl
use Fcntl ':mode';
    if (($dev,$ino,$mode) = lstat($_)) {
        $permissions = sprintf "%04o", S_IMODE($mode);
        printf("$_:  $permissions\n");

For example, if you run it against your $HOME directory, you’ll get something like this:

/home/username: 0755

Posted under DevOps tagged as DevOps, Perl, Linux