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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:42:59+00:00 2026-06-13T18:42:59+00:00

The Erlang docs for file:read_file_info/1 state file permissions [are] the sum and other bits…may

  • 0

The Erlang docs for file:read_file_info/1 state “file permissions [are] the sum” and “other bits…may be set”, not instilling confidence. And, Google has not been my friend here.

I’m looking to take the mode returned by file:read_file_info/1, e.g. 33188, on a Linux machine and convert it into something more human readable and/or recognizable, like rw-r--r-- or 644.

Any tips, links, or directions greatly appreciated.

  • 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-06-13T18:43:00+00:00Added an answer on June 13, 2026 at 6:43 pm

    The short way:

    io_lib:format("~.8B", [Mode]).
    

    … or:

    io_lib:format("~.8B", [Mode band 8#777]).
    

    For Mode = 33204 these two will give you respectively: ["100664"] and ["664"].

    The long way:

    print(Mode) ->
        print(Mode band 8#777, []).
    
    print(0, Acc) when length(Acc) =:= 9 ->
        Acc;
    print(N, Acc) ->
        Char = perm(N band 1, length(Acc) rem 3),
        print(N bsr 1, [Char | Acc]).
    
    perm(0, _) ->
        $-;
    perm(1, 0) ->
        $x;
    perm(1, 1) ->
        $w;
    perm(1, 2) ->
        $r.
    

    This one (function print/1) for Mode = 33204 will give you this as result: "rw-rw-r--".


    If something was unclear for one, I’ll try to expound basic things behind the snippets which I have provided.

    As @macintux mentioned already, the 33204 in fact is a decimal representation of the octal number 100664. These three lowest octal digits (664) there is probably what you need, and so we get them with bitwise and (band) operation with the highest number which fits in three octal digits (8#777). That’s why short way is so short – you just tell erlang to convert Mode to string as if it was the octal number.

    The second representation you’ve mentioned (like rw-rw-r--, something that ls spits out) is easily reproducible from binary representation of the Mode number. Note that three octal digits will give you exactly nine binary digits (8#644 = 2#110110100). In fact this is the string rwxrwxrwx where each element replaced by - if corresponding digit equals 0. If digit is 1 the element remains untouched.

    So there is slightly cleaner approach to achieve this:

    print(Mode) ->
        print(Mode band 8#777, lists:reverse("rwxrwxrwx"), []).
    
    print(0, [], Acc) ->
        Acc;
    print(N, [Char0 | Rest], Acc) ->
        Char = char(N band 1, Char0),
        print(N bsr 1, Rest, [Char | Acc]).
    
    char(0, _) ->
        $-;
    char(1, C) ->
        C.
    

    I hope you got the point. Anyway feel free to ask any questions in comments if you doubt.

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

Sidebar

Related Questions

The Erlang digraphs module surprised me by mutating state. When dealing with other data
The Erlang documentation states the following about gen_servers: ... Note that for any other
I have a file .erlang in the current dir I run erl shell that
I have this Erlang code: not lists:any(fun(Condition) ->Condition(Message) end, Conditions). Can anyone please explain
I was reading the erlang documentation about file io and saw this: On operating
In the recent Erlang R14, inets' file httpd.hrl has been moved from: src/httpd.hrl to:
I can start an Erlang file either via the command line or bash script:
When compiling an erlang file with erlc I can add additional include directories like
In the Erlang shell it shows riak_pb_client as not existing when trying to test
Erlang seems to be very low level and performant on networks, but does not

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.