cmdline Unix Permissions bits calculator

The name of the pictureThe name of the pictureThe name of the pictureClash 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!










share|improve this question























  • 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










  • 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















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!










share|improve this question























  • 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










  • 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













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!










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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










  • 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

















  • 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










  • 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
















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











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
)





share|improve this answer






















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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
)





share|improve this answer






















  • 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














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
)





share|improve this answer






















  • 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












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
)





share|improve this answer














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
)






share|improve this answer














share|improve this answer



share|improve this answer








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 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















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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay