Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:31:43+00:00 2026-05-27T18:31:43+00:00

For a unix file, I want to know if Group or World has write

  • 0

For a unix file, I want to know if Group or World has write permission on the file.

I’ve been thinking on these lines:

my $fpath   = "orion.properties";
my $info    = stat($fpath) ;
my $retMode = $info->mode;
$retMode = $retMode & 0777;

if(($retMode & 006)) {
  # Code comes here if World has r/w/x on the file
} 

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:31:44+00:00Added an answer on May 27, 2026 at 6:31 pm

    You are close with your proposal – the usage of stat is a little off (but on second thoughts, you must be using File::stat; it helps if your code is complete), the mask constant is faulty, and the comment leaves somewhat to be desired:

    use strict;
    use warnings;
    use File::stat;
    
    my $fpath   = "orion.properties";
    my $info    = stat($fpath);
    my $retMode = $info->mode;
    $retMode = $retMode & 0777;
    
    if ($retMode & 002) {
        # Code comes here if World has write permission on the file
    }     
    if ($retMode & 020) {
        # Code comes here if Group has write permission on the file
    }
    if ($retMode & 022) {
        # Code comes here if Group or World (or both) has write permission on the file
    }
    if ($retMode & 007) {
        # Code comes here if World has read, write *or* execute permission on the file
    } 
    if ($retMode & 006) {
        # Code comes here if World has read or write permission on the file
    } 
    if (($retMode & 007) == 007) {
        # Code comes here if World has read, write *and* execute permission on the file
    } 
    if (($retMode & 006) == 006) {
        # Code comes here if World has read *and* write permission on the file
    }
    if (($retMode & 022) == 022) {
        # Code comes here if Group *and* World both have write permission on the file
    }
    

    The terminology in the question title ‘How to check in Perl if the file permission is greater than 755? i.e. Group/World has write permission’ is a little suspect.

    The file might have permissions 022 (or, more plausibly, 622), and that would include group and world write permission, but neither value can reasonably be claimed to be ‘greater than 755’.

    A set of concepts that I’ve found useful is:

    • Set bits – bits in the permissions field that must be 1.
    • Reset bits – bits in the permissions field that must be 0.
    • Don’t care bits – bits that can be set or reset.

    For example, for a data file, I might require:

    • Set 0644 (owner can read and write; group and other can read).
    • Reset 0133 (owner cannot execute – it is a data file; group and other cannot write or execute).

    More likely, for a data file, I might require:

    • Set 0400 (owner must be able to read).
    • Reset 0133 (no-one can execute; group and other cannot write).
    • Don’t care 0244 (does not matter whether the owner can write; does not matter whether group or others can read).

    Directories are slightly different: execute permission means that you can make the directory your current directory, or access files in the directory if you know their name, while read permission means you can find out what files are in the directory, but you can’t access them without execute permission too. Hence, you might have:

    • Set 0500 (owner must be able to read and use files in the directory).
    • Reset 0022 (group and others must not be able to modify the directory – delete or add files).
    • Don’t care 0255 (don’t care whether user can create files; don’t care whether group or other can list or use files).

    Note that the set and reset bits must be disjoint (($set & $rst) == 0)), the sum of the bits will always be 0777; the “don’t care” bits can be computed from 0777 & ~($set | $rst).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unix 'file' command has a -0 option to output a null character after a
I want to print a head of a file in R. I know how
I am new to unix and shell. I want to know how to draw
UNIX file-locking is dead-easy: The operating system assumes that you know what you are
I want to simulate this Unix command : cat file.txt | sort | tail
I'm trying to comprehend the Unix file system on my OSX. I'm following wikipedia
INFORMIX-SQL 4.1 - There's this ASCII UNIX file called passwd in /usr/informix/etc which holds
How to create a .so and .a file in UNIX. Do we have any
I understand that a directory is just a file in unix that contains the
Network file systems are offered by Windows and (L)Unix. Is there one for IBM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.