File Permissions

bash, 59 53 bytes

chmod ${1:1} a>a;stat -c%A a|sed s/./${1:0:1}/|tr f -

Right tool for the job?

Thanks to Dennis for saving 5 bytes and HTNW for saving one.

Try it online!

chmod ${1:1} a>a;  # call chmod with the input with its first character removed
                   # note that the redirection creates the file a *before* the
                   #   chmod is run, because of the way bash works
stat -c%A a|       # get the human readable access rights
sed s/./${1:0:1}/  # replace the first character with the first char of input
|tr f -            # transliterate, replacing f with -

Python 2, 78 bytes

lambda a,*b:[a,'-'][a=='f']+''.join('-r'[x/4]+'-w-w'[x/2]+'-x'[x%2]for x in b)

Takes input as a character and three ints.
Try it online!

Explanation

[a,'-'][a=='f'] takes either the input character or -, if the character is f.
'-r'[x/4]+'-w-w'[x/2]+'-x'[x%2] is essentially an octal conversion to get the rwx string.


Jelly, 19 bytes

“rwx“-”Œp⁺;Ṁ⁾f-yị@~

Try it online!

How it works

“rwx“-”Œp⁺;Ṁ⁾f-yị@~  Main link. Argument: s (string)

“rwx“-”              Set the return value to ["rwx, "-"].
       Œp            Take the Cartesian product, yielding ["r-", "w-", "x-"].
         ⁺           Take the Cartesian product, yielding
                     ["rwx", "rw-", "r-x", "r--", "-wx", "-w-", "--x", "---"].
          ;Ṁ         Append the maximum of s (the letter).
            ⁾f-y     Translate 'f' to '-'.
                  ~  Map bitwise NOT over s.
                     This maps the letter to 0, because it cannot be cast to int,
                     and each digit d to ~d = -(d+1).
                ị@   Retrieve the results from the array to the left at the indices
                     calculated to the right.
                     Indexing is modular and 1-based, so the letter from s is at
                     index 0, "---" at index -1, ..., and "rwx" at index -8.

Tags:

Code Golf