cmdline Unix Permissions bits calculator
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'd like to convert the Unix Permissions bits from octal to symbolic mode and viceversa.
eg.:
$ mode-encode 'ugo+rwx'
0000
$ mode-decode 0000
ugo+rwx
I know there are online permission bits calculators and chmod
supports passing the bits in both ways, but i'd like a bash code snippet i can use with commands that does not support the symbolic mode.
EDIT: i'd like to get the permission bits, not the umask!
permissions umask
 |Â
show 1 more comment
up vote
1
down vote
favorite
I'd like to convert the Unix Permissions bits from octal to symbolic mode and viceversa.
eg.:
$ mode-encode 'ugo+rwx'
0000
$ mode-decode 0000
ugo+rwx
I know there are online permission bits calculators and chmod
supports passing the bits in both ways, but i'd like a bash code snippet i can use with commands that does not support the symbolic mode.
EDIT: i'd like to get the permission bits, not the umask!
permissions umask
Note that for some values of the symbolic forms, the result will depend on the current umask. like forumask +r
, orumask g=u
(that one not supported by all implementation even though it's POSIX)
â Stéphane Chazelas
Aug 29 at 12:39
ugo+rwx
gives 0000 by the way, not 0777
â Stéphane Chazelas
Aug 29 at 12:41
Your latest edit makes it a bit confusing. Isn't @schily's answer what you want? If you want the complement, you can always doprintf '%on' "$((value ^ 511))"
â Stéphane Chazelas
Aug 30 at 14:19
indeed i've noticed the results are inverted from what i expected (the previous examples were actually correct), so i had to add complement step to the @schily's answer
â eadmaster
Aug 30 at 14:28
It's still unclear, all thea+x
,go=u
symbolic notations are relative, what do you want them to be relative to? Your question is now completely different from the original one which invalidates all the current answers. I'd suggest you revert this one to the original and post a separate question for your new requirements.
â Stéphane Chazelas
Aug 30 at 14:45
 |Â
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'd like to convert the Unix Permissions bits from octal to symbolic mode and viceversa.
eg.:
$ mode-encode 'ugo+rwx'
0000
$ mode-decode 0000
ugo+rwx
I know there are online permission bits calculators and chmod
supports passing the bits in both ways, but i'd like a bash code snippet i can use with commands that does not support the symbolic mode.
EDIT: i'd like to get the permission bits, not the umask!
permissions umask
I'd like to convert the Unix Permissions bits from octal to symbolic mode and viceversa.
eg.:
$ mode-encode 'ugo+rwx'
0000
$ mode-decode 0000
ugo+rwx
I know there are online permission bits calculators and chmod
supports passing the bits in both ways, but i'd like a bash code snippet i can use with commands that does not support the symbolic mode.
EDIT: i'd like to get the permission bits, not the umask!
permissions umask
permissions umask
edited Aug 30 at 14:30
asked Aug 29 at 11:20
eadmaster
4243720
4243720
Note that for some values of the symbolic forms, the result will depend on the current umask. like forumask +r
, orumask g=u
(that one not supported by all implementation even though it's POSIX)
â Stéphane Chazelas
Aug 29 at 12:39
ugo+rwx
gives 0000 by the way, not 0777
â Stéphane Chazelas
Aug 29 at 12:41
Your latest edit makes it a bit confusing. Isn't @schily's answer what you want? If you want the complement, you can always doprintf '%on' "$((value ^ 511))"
â Stéphane Chazelas
Aug 30 at 14:19
indeed i've noticed the results are inverted from what i expected (the previous examples were actually correct), so i had to add complement step to the @schily's answer
â eadmaster
Aug 30 at 14:28
It's still unclear, all thea+x
,go=u
symbolic notations are relative, what do you want them to be relative to? Your question is now completely different from the original one which invalidates all the current answers. I'd suggest you revert this one to the original and post a separate question for your new requirements.
â Stéphane Chazelas
Aug 30 at 14:45
 |Â
show 1 more comment
Note that for some values of the symbolic forms, the result will depend on the current umask. like forumask +r
, orumask g=u
(that one not supported by all implementation even though it's POSIX)
â Stéphane Chazelas
Aug 29 at 12:39
ugo+rwx
gives 0000 by the way, not 0777
â Stéphane Chazelas
Aug 29 at 12:41
Your latest edit makes it a bit confusing. Isn't @schily's answer what you want? If you want the complement, you can always doprintf '%on' "$((value ^ 511))"
â Stéphane Chazelas
Aug 30 at 14:19
indeed i've noticed the results are inverted from what i expected (the previous examples were actually correct), so i had to add complement step to the @schily's answer
â eadmaster
Aug 30 at 14:28
It's still unclear, all thea+x
,go=u
symbolic notations are relative, what do you want them to be relative to? Your question is now completely different from the original one which invalidates all the current answers. I'd suggest you revert this one to the original and post a separate question for your new requirements.
â Stéphane Chazelas
Aug 30 at 14:45
Note that for some values of the symbolic forms, the result will depend on the current umask. like for
umask +r
, or umask g=u
(that one not supported by all implementation even though it's POSIX)â Stéphane Chazelas
Aug 29 at 12:39
Note that for some values of the symbolic forms, the result will depend on the current umask. like for
umask +r
, or umask g=u
(that one not supported by all implementation even though it's POSIX)â Stéphane Chazelas
Aug 29 at 12:39
ugo+rwx
gives 0000 by the way, not 0777â Stéphane Chazelas
Aug 29 at 12:41
ugo+rwx
gives 0000 by the way, not 0777â Stéphane Chazelas
Aug 29 at 12:41
Your latest edit makes it a bit confusing. Isn't @schily's answer what you want? If you want the complement, you can always do
printf '%on' "$((value ^ 511))"
â Stéphane Chazelas
Aug 30 at 14:19
Your latest edit makes it a bit confusing. Isn't @schily's answer what you want? If you want the complement, you can always do
printf '%on' "$((value ^ 511))"
â Stéphane Chazelas
Aug 30 at 14:19
indeed i've noticed the results are inverted from what i expected (the previous examples were actually correct), so i had to add complement step to the @schily's answer
â eadmaster
Aug 30 at 14:28
indeed i've noticed the results are inverted from what i expected (the previous examples were actually correct), so i had to add complement step to the @schily's answer
â eadmaster
Aug 30 at 14:28
It's still unclear, all the
a+x
, go=u
symbolic notations are relative, what do you want them to be relative to? Your question is now completely different from the original one which invalidates all the current answers. I'd suggest you revert this one to the original and post a separate question for your new requirements.â Stéphane Chazelas
Aug 30 at 14:45
It's still unclear, all the
a+x
, go=u
symbolic notations are relative, what do you want them to be relative to? Your question is now completely different from the original one which invalidates all the current answers. I'd suggest you revert this one to the original and post a separate question for your new requirements.â Stéphane Chazelas
Aug 30 at 14:45
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
2
down vote
In any POSIX shell, you can call:
savmask=$(umask)
umask someval
umask -S # outputs the symbolic form
umask # outputs the octal form
umask -- "$savmask"
You could put this into a function
printmask()
savmask=$(umask)
Or use a subshell to avoid having to save and restore the umask:
printmask() (
umask -- "$1?Please specify a umask" || exit
umask -S
umask
)
ok, i've addedumask 0777
at the beginning of the lastprintmask
function to always have the full mask.
â eadmaster
Aug 29 at 13:26
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
In any POSIX shell, you can call:
savmask=$(umask)
umask someval
umask -S # outputs the symbolic form
umask # outputs the octal form
umask -- "$savmask"
You could put this into a function
printmask()
savmask=$(umask)
Or use a subshell to avoid having to save and restore the umask:
printmask() (
umask -- "$1?Please specify a umask" || exit
umask -S
umask
)
ok, i've addedumask 0777
at the beginning of the lastprintmask
function to always have the full mask.
â eadmaster
Aug 29 at 13:26
add a comment |Â
up vote
2
down vote
In any POSIX shell, you can call:
savmask=$(umask)
umask someval
umask -S # outputs the symbolic form
umask # outputs the octal form
umask -- "$savmask"
You could put this into a function
printmask()
savmask=$(umask)
Or use a subshell to avoid having to save and restore the umask:
printmask() (
umask -- "$1?Please specify a umask" || exit
umask -S
umask
)
ok, i've addedumask 0777
at the beginning of the lastprintmask
function to always have the full mask.
â eadmaster
Aug 29 at 13:26
add a comment |Â
up vote
2
down vote
up vote
2
down vote
In any POSIX shell, you can call:
savmask=$(umask)
umask someval
umask -S # outputs the symbolic form
umask # outputs the octal form
umask -- "$savmask"
You could put this into a function
printmask()
savmask=$(umask)
Or use a subshell to avoid having to save and restore the umask:
printmask() (
umask -- "$1?Please specify a umask" || exit
umask -S
umask
)
In any POSIX shell, you can call:
savmask=$(umask)
umask someval
umask -S # outputs the symbolic form
umask # outputs the octal form
umask -- "$savmask"
You could put this into a function
printmask()
savmask=$(umask)
Or use a subshell to avoid having to save and restore the umask:
printmask() (
umask -- "$1?Please specify a umask" || exit
umask -S
umask
)
edited Aug 29 at 12:52
Stéphane Chazelas
286k53527866
286k53527866
answered Aug 29 at 11:37
schily
9,63131437
9,63131437
ok, i've addedumask 0777
at the beginning of the lastprintmask
function to always have the full mask.
â eadmaster
Aug 29 at 13:26
add a comment |Â
ok, i've addedumask 0777
at the beginning of the lastprintmask
function to always have the full mask.
â eadmaster
Aug 29 at 13:26
ok, i've added
umask 0777
at the beginning of the last printmask
function to always have the full mask.â eadmaster
Aug 29 at 13:26
ok, i've added
umask 0777
at the beginning of the last printmask
function to always have the full mask.â eadmaster
Aug 29 at 13:26
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465483%2fcmdline-unix-permissions-bits-calculator%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Note that for some values of the symbolic forms, the result will depend on the current umask. like for
umask +r
, orumask g=u
(that one not supported by all implementation even though it's POSIX)â Stéphane Chazelas
Aug 29 at 12:39
ugo+rwx
gives 0000 by the way, not 0777â Stéphane Chazelas
Aug 29 at 12:41
Your latest edit makes it a bit confusing. Isn't @schily's answer what you want? If you want the complement, you can always do
printf '%on' "$((value ^ 511))"
â Stéphane Chazelas
Aug 30 at 14:19
indeed i've noticed the results are inverted from what i expected (the previous examples were actually correct), so i had to add complement step to the @schily's answer
â eadmaster
Aug 30 at 14:28
It's still unclear, all the
a+x
,go=u
symbolic notations are relative, what do you want them to be relative to? Your question is now completely different from the original one which invalidates all the current answers. I'd suggest you revert this one to the original and post a separate question for your new requirements.â Stéphane Chazelas
Aug 30 at 14:45