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 7417293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:40:21+00:00 2026-05-29T07:40:21+00:00

Here’s something I don’t understand. In perl, let’s say I have a file(handle) $file

  • 0

Here’s something I don’t understand. In perl, let’s say I have a file(handle) $file then

my $mode = (stat $file)[2];

gives the mode of the file, described as the type and permissions. Then, in the docs for chmod, it is recommended to mask off the file type when sending the mode from stat to chmod like, e.g.

my $perm = (stat $file)[2] & 07777;
chmod($perm | 0600, $file);

Similarly, the docs for mkdir indicate that mkdir(FILENAME,MASK) “creates the directory specified by FILENAME, with permissions specified by MASK (as modified by umask).”

Alrighty. Here’s what I don’t get. On the command line, I make a dir temp in my home directory, with default permissions drwxr-xr-x (octal 0755). Then

  1. perl’s stat tells me that the mode of this directory is 16877.
  2. $perms = (stat 'temp')[2] & 07777; returns 493.
  3. $perms = sprintf("%04o",(stat 'temp')[2] & 07777); returns 0755.

I expected chmod(x,'temp') with x = (1) and (2) to change the permissions on temp/ to something screwy. But, all three give drwxr-xr-x (admittedly with (3) you must do chmod(oct($perms),'temp);) Similarly, mkdir(temp,16877), mkdir(temp,493), mkdir(temp,0755) all give permissions drwxr-xr-x on temp/.

So, my question: what’s really going on? How is it that chmod and mkdir take these three different values and set the same permissions on temp/? I realize one answer might be ‘there’s more than one way to do it’, and that’s fine as far as it goes, but I’d like to understand what’s happening here. Also, what is the recommended way to pass permissions values to these functions? 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-29T07:40:22+00:00Added an answer on May 29, 2026 at 7:40 am

    493 decimal = 0755 octal, so this is a non issue – they are identical.
    16877 decimal = 40755 octal.
    Looks like chmod only uses the bits that it needs and ignores anything in the higher order bits.

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

Sidebar

Related Questions

Here an example of my checkbox list http://jsfiddle.net/YnM2f/ Let's say I check on G
Here is my code (Say we have a single button on the page that
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here is an example: I have a file 1.js, which has some functions. I
I have just tried to save a simple *.rtf file with some websites and
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here is an example: I write html code inside of textarea, then I swap
Here is an example: I have the generic type called Account. I wish to
Here I have an int x=3; NSLog(@%i, x); How to have it displayed like

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.