D
D
Dmitry Bystrov2018-11-29 19:15:56
linux
Dmitry Bystrov, 2018-11-29 19:15:56

How to get octal/character form of permissions?

Hello!
There is a task:

Write an ls2oct function that translates a set of permissions from the character form output from the ls -l command (for example, "rwxr-xr--") to the equivalent octal value. Then write the inverse function oct2ls.

How can I write ls -l to an array or variable?
Are there any ready-made functions, or do you need to write a character value parser yourself and translate everything into octal values?
To write a reverse translation, I need permissions to be written in octal.
How can this be achieved?
Maybe some literature? In textbooks I found only a table of octal values.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vman, 2018-11-29
@Teshuhack

Everything is simple here, you need to split a string of 9 characters into 3 octets
1 = rwx
2 = rx
3 = r--
Then replace and sum the characters in each octet

r = 4
w = 2
x = 1
- = 0

the output will be 754

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question