Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Scripting >> Python >> Examples >> Function to convert Unix octal permissions to string (rwx) permissions


def octal_to_string(octal):
    result = ""
    value_letters = [(4,"r"),(2,"w"),(1,"x")]
    # Iterate over each of the digits in octal
    for odigit in [int(n) for n in str(octal)]:
        # Check for each of the permissions values
        for value, letter in value_letters:
            if odigit >= value:
                result += letter
                odigit -= value
            else:
                result += "-"
    return result
   
print(octal_to_string(755)) # should return rwxr-xr-x

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]