计算Linux权限掩码umask值
创建文件默认最大权限为666 (-rw-rw-rw-),默认创建的文件没有可执行权限x位。
创建目录默认最大权限777(-rwx-rwx-rwx),默认创建的目录属主是有x权限,允许用户进入。
简单的python脚本计算umask对应的文件和目录权限
#!/usr/bin/python # -*- coding: utf-8 -*- #author:xiaoxiaoleo #url:http://www.cnblogs.com/xiaoxiaoleo/ import itertools def file_perm(umask): out_per_list = [] in_perm_list = '666' umask_list = list(umask) for num in range(len(umask_list)): if (int(umask_list[num]) % 2) == 0: out_per_list.append(int(in_perm_list[num]) - int(umask_list[num])) if (int(umask_list[num]) % 2) != 0: out_per_list.append(int(in_perm_list[num]) - int(umask_list[num]) + 1 ) return ''.join(str(i) for i in out_per_list) def dir_perm(umask): out_per_list = [] in_perm_list = '777' umask_list = list(umask) for num in range(len(umask_list)): out_per_list.append(int(in_perm_list[num]) - int(umask_list[num])) return ''.join(str(i) for i in out_per_list) def calc_perm(umask): print 'umask:%s file:%s dir:%s' % (umask,file_perm(umask),dir_perm(umask)) if __name__ == '__main__': calc_perm('123')
umask与文件目录权限对照表
umask:000 file:666 dir:777 umask:001 file:666 dir:776 umask:002 file:664 dir:775 umask:003 file:664 dir:774 umask:004 file:662 dir:773 umask:005 file:662 dir:772 umask:006 file:660 dir:771 umask:007 file:660 dir:770 umask:010 file:666 dir:767 umask:011 file:666 dir:766 umask:012 file:664 dir:765 umask:013 file:664 dir:764 umask:014 file:662 dir:763 umask:015 file:662 dir:762 umask:016 file:660 dir:761 umask:017 file:660 dir:760 umask:020 file:646 dir:757 umask:021 file:646 dir:756 umask:022 file:644 dir:755 umask:023 file:644 dir:754 umask:024 file:642 dir:753 umask:025 file:642 dir:752 umask:026 file:640 dir:751 umask:027 file:640 dir:750 umask:030 file:646 dir:747 umask:031 file:646 dir:746 umask:032 file:644 dir:745 umask:033 file:644 dir:744 umask:034 file:642 dir:743 umask:035 file:642 dir:742 umask:036 file:640 dir:741 umask:037 file:640 dir:740 umask:040 file:626 dir:737 umask:041 file:626 dir:736 umask:042 file:624 dir:735 umask:043 file:624 dir:734 umask:044 file:622 dir:733 umask:045 file:622 dir:732 umask:046 file:620 dir:731 umask:047 file:620 dir:730 umask:050 file:626 dir:727 umask:051 file:626 dir:726 umask:052 file:624 dir:725 umask:053 file:624 dir:724 umask:054 file:622 dir:723 umask:055 file:622 dir:722 umask:056 file:620 dir:721 umask:057 file:620 dir:720 umask:060 file:606 dir:717 umask:061 file:606 dir:716 umask:062 file:604 dir:715 umask:063 file:604 dir:714 umask:064 file:602 dir:713 umask:065 file:602 dir:712 umask:066 file:600 dir:711 umask:067 file:600 dir:710 umask:070 file:606 dir:707 umask:071 file:606 dir:706 umask:072 file:604 dir:705 umask:073 file:604 dir:704 umask:074 file:602 dir:703 umask:075 file:602 dir:702 umask:076 file:600 dir:701 umask:077 file:600 dir:700 umask:100 file:666 dir:677 umask:101 file:666 dir:676 umask:102 file:664 dir:675 umask:103 file:664 dir:674 umask:104 file:662 dir:673 umask:105 file:662 dir:672 umask:106 file:660 dir:671 umask:107 file:660 dir:670 umask:110 file:666 dir:667 umask:111 file:666 dir:666 umask:112 file:664 dir:665 umask:113 file:664 dir:664 umask:114 file:662 dir:663 umask:115 file:662 dir:662 umask:116 file:660 dir:661 umask:117 file:660 dir:660 umask:120 file:646 dir:657 umask:121 file:646 dir:656 umask:122 file:644 dir:655 umask:123 file:644 dir:654 umask:124 file:642 dir:653 umask:125 file:642 dir:652 umask:126 file:640 dir:651 umask:127 file:640 dir:650 umask:130 file:646 dir:647 umask:131 file:646 dir:646 umask:132 file:644 dir:645 umask:133 file:644 dir:644 umask:134 file:642 dir:643 umask:135 file:642 dir:642 umask:136 file:640 dir:641 umask:137 file:640 dir:640 umask:140 file:626 dir:637 umask:141 file:626 dir:636 umask:142 file:624 dir:635 umask:143 file:624 dir:634 umask:144 file:622 dir:633 umask:145 file:622 dir:632 umask:146 file:620 dir:631 umask:147 file:620 dir:630 umask:150 file:626 dir:627 umask:151 file:626 dir:626 umask:152 file:624 dir:625 umask:153 file:624 dir:624 umask:154 file:622 dir:623 umask:155 file:622 dir:622 umask:156 file:620 dir:621 umask:157 file:620 dir:620 umask:160 file:606 dir:617 umask:161 file:606 dir:616 umask:162 file:604 dir:615 umask:163 file:604 dir:614 umask:164 file:602 dir:613 umask:165 file:602 dir:612 umask:166 file:600 dir:611 umask:167 file:600 dir:610 umask:170 file:606 dir:607 umask:171 file:606 dir:606 umask:172 file:604 dir:605 umask:173 file:604 dir:604 umask:174 file:602 dir:603 umask:175 file:602 dir:602 umask:176 file:600 dir:601 umask:177 file:600 dir:600 umask:200 file:466 dir:577 umask:201 file:466 dir:576 umask:202 file:464 dir:575 umask:203 file:464 dir:574 umask:204 file:462 dir:573 umask:205 file:462 dir:572 umask:206 file:460 dir:571 umask:207 file:460 dir:570 umask:210 file:466 dir:567 umask:211 file:466 dir:566 umask:212 file:464 dir:565 umask:213 file:464 dir:564 umask:214 file:462 dir:563 umask:215 file:462 dir:562 umask:216 file:460 dir:561 umask:217 file:460 dir:560 umask:220 file:446 dir:557 umask:221 file:446 dir:556 umask:222 file:444 dir:555 umask:223 file:444 dir:554 umask:224 file:442 dir:553 umask:225 file:442 dir:552 umask:226 file:440 dir:551 umask:227 file:440 dir:550 umask:230 file:446 dir:547 umask:231 file:446 dir:546 umask:232 file:444 dir:545 umask:233 file:444 dir:544 umask:234 file:442 dir:543 umask:235 file:442 dir:542 umask:236 file:440 dir:541 umask:237 file:440 dir:540 umask:240 file:426 dir:537 umask:241 file:426 dir:536 umask:242 file:424 dir:535 umask:243 file:424 dir:534 umask:244 file:422 dir:533 umask:245 file:422 dir:532 umask:246 file:420 dir:531 umask:247 file:420 dir:530 umask:250 file:426 dir:527 umask:251 file:426 dir:526 umask:252 file:424 dir:525 umask:253 file:424 dir:524 umask:254 file:422 dir:523 umask:255 file:422 dir:522 umask:256 file:420 dir:521 umask:257 file:420 dir:520 umask:260 file:406 dir:517 umask:261 file:406 dir:516 umask:262 file:404 dir:515 umask:263 file:404 dir:514 umask:264 file:402 dir:513 umask:265 file:402 dir:512 umask:266 file:400 dir:511 umask:267 file:400 dir:510 umask:270 file:406 dir:507 umask:271 file:406 dir:506 umask:272 file:404 dir:505 umask:273 file:404 dir:504 umask:274 file:402 dir:503 umask:275 file:402 dir:502 umask:276 file:400 dir:501 umask:277 file:400 dir:500 umask:300 file:466 dir:477 umask:301 file:466 dir:476 umask:302 file:464 dir:475 umask:303 file:464 dir:474 umask:304 file:462 dir:473 umask:305 file:462 dir:472 umask:306 file:460 dir:471 umask:307 file:460 dir:470 umask:310 file:466 dir:467 umask:311 file:466 dir:466 umask:312 file:464 dir:465 umask:313 file:464 dir:464 umask:314 file:462 dir:463 umask:315 file:462 dir:462 umask:316 file:460 dir:461 umask:317 file:460 dir:460 umask:320 file:446 dir:457 umask:321 file:446 dir:456 umask:322 file:444 dir:455 umask:323 file:444 dir:454 umask:324 file:442 dir:453 umask:325 file:442 dir:452 umask:326 file:440 dir:451 umask:327 file:440 dir:450 umask:330 file:446 dir:447 umask:331 file:446 dir:446 umask:332 file:444 dir:445 umask:333 file:444 dir:444 umask:334 file:442 dir:443 umask:335 file:442 dir:442 umask:336 file:440 dir:441 umask:337 file:440 dir:440 umask:340 file:426 dir:437 umask:341 file:426 dir:436 umask:342 file:424 dir:435 umask:343 file:424 dir:434 umask:344 file:422 dir:433 umask:345 file:422 dir:432 umask:346 file:420 dir:431 umask:347 file:420 dir:430 umask:350 file:426 dir:427 umask:351 file:426 dir:426 umask:352 file:424 dir:425 umask:353 file:424 dir:424 umask:354 file:422 dir:423 umask:355 file:422 dir:422 umask:356 file:420 dir:421 umask:357 file:420 dir:420 umask:360 file:406 dir:417 umask:361 file:406 dir:416 umask:362 file:404 dir:415 umask:363 file:404 dir:414 umask:364 file:402 dir:413 umask:365 file:402 dir:412 umask:366 file:400 dir:411 umask:367 file:400 dir:410 umask:370 file:406 dir:407 umask:371 file:406 dir:406 umask:372 file:404 dir:405 umask:373 file:404 dir:404 umask:374 file:402 dir:403 umask:375 file:402 dir:402 umask:376 file:400 dir:401 umask:377 file:400 dir:400 umask:400 file:266 dir:377 umask:401 file:266 dir:376 umask:402 file:264 dir:375 umask:403 file:264 dir:374 umask:404 file:262 dir:373 umask:405 file:262 dir:372 umask:406 file:260 dir:371 umask:407 file:260 dir:370 umask:410 file:266 dir:367 umask:411 file:266 dir:366 umask:412 file:264 dir:365 umask:413 file:264 dir:364 umask:414 file:262 dir:363 umask:415 file:262 dir:362 umask:416 file:260 dir:361 umask:417 file:260 dir:360 umask:420 file:246 dir:357 umask:421 file:246 dir:356 umask:422 file:244 dir:355 umask:423 file:244 dir:354 umask:424 file:242 dir:353 umask:425 file:242 dir:352 umask:426 file:240 dir:351 umask:427 file:240 dir:350 umask:430 file:246 dir:347 umask:431 file:246 dir:346 umask:432 file:244 dir:345 umask:433 file:244 dir:344 umask:434 file:242 dir:343 umask:435 file:242 dir:342 umask:436 file:240 dir:341 umask:437 file:240 dir:340 umask:440 file:226 dir:337 umask:441 file:226 dir:336 umask:442 file:224 dir:335 umask:443 file:224 dir:334 umask:444 file:222 dir:333 umask:445 file:222 dir:332 umask:446 file:220 dir:331 umask:447 file:220 dir:330 umask:450 file:226 dir:327 umask:451 file:226 dir:326 umask:452 file:224 dir:325 umask:453 file:224 dir:324 umask:454 file:222 dir:323 umask:455 file:222 dir:322 umask:456 file:220 dir:321 umask:457 file:220 dir:320 umask:460 file:206 dir:317 umask:461 file:206 dir:316 umask:462 file:204 dir:315 umask:463 file:204 dir:314 umask:464 file:202 dir:313 umask:465 file:202 dir:312 umask:466 file:200 dir:311 umask:467 file:200 dir:310 umask:470 file:206 dir:307 umask:471 file:206 dir:306 umask:472 file:204 dir:305 umask:473 file:204 dir:304 umask:474 file:202 dir:303 umask:475 file:202 dir:302 umask:476 file:200 dir:301 umask:477 file:200 dir:300 umask:500 file:266 dir:277 umask:501 file:266 dir:276 umask:502 file:264 dir:275 umask:503 file:264 dir:274 umask:504 file:262 dir:273 umask:505 file:262 dir:272 umask:506 file:260 dir:271 umask:507 file:260 dir:270 umask:510 file:266 dir:267 umask:511 file:266 dir:266 umask:512 file:264 dir:265 umask:513 file:264 dir:264 umask:514 file:262 dir:263 umask:515 file:262 dir:262 umask:516 file:260 dir:261 umask:517 file:260 dir:260 umask:520 file:246 dir:257 umask:521 file:246 dir:256 umask:522 file:244 dir:255 umask:523 file:244 dir:254 umask:524 file:242 dir:253 umask:525 file:242 dir:252 umask:526 file:240 dir:251 umask:527 file:240 dir:250 umask:530 file:246 dir:247 umask:531 file:246 dir:246 umask:532 file:244 dir:245 umask:533 file:244 dir:244 umask:534 file:242 dir:243 umask:535 file:242 dir:242 umask:536 file:240 dir:241 umask:537 file:240 dir:240 umask:540 file:226 dir:237 umask:541 file:226 dir:236 umask:542 file:224 dir:235 umask:543 file:224 dir:234 umask:544 file:222 dir:233 umask:545 file:222 dir:232 umask:546 file:220 dir:231 umask:547 file:220 dir:230 umask:550 file:226 dir:227 umask:551 file:226 dir:226 umask:552 file:224 dir:225 umask:553 file:224 dir:224 umask:554 file:222 dir:223 umask:555 file:222 dir:222 umask:556 file:220 dir:221 umask:557 file:220 dir:220 umask:560 file:206 dir:217 umask:561 file:206 dir:216 umask:562 file:204 dir:215 umask:563 file:204 dir:214 umask:564 file:202 dir:213 umask:565 file:202 dir:212 umask:566 file:200 dir:211 umask:567 file:200 dir:210 umask:570 file:206 dir:207 umask:571 file:206 dir:206 umask:572 file:204 dir:205 umask:573 file:204 dir:204 umask:574 file:202 dir:203 umask:575 file:202 dir:202 umask:576 file:200 dir:201 umask:577 file:200 dir:200 umask:600 file:066 dir:177 umask:601 file:066 dir:176 umask:602 file:064 dir:175 umask:603 file:064 dir:174 umask:604 file:062 dir:173 umask:605 file:062 dir:172 umask:606 file:060 dir:171 umask:607 file:060 dir:170 umask:610 file:066 dir:167 umask:611 file:066 dir:166 umask:612 file:064 dir:165 umask:613 file:064 dir:164 umask:614 file:062 dir:163 umask:615 file:062 dir:162 umask:616 file:060 dir:161 umask:617 file:060 dir:160 umask:620 file:046 dir:157 umask:621 file:046 dir:156 umask:622 file:044 dir:155 umask:623 file:044 dir:154 umask:624 file:042 dir:153 umask:625 file:042 dir:152 umask:626 file:040 dir:151 umask:627 file:040 dir:150 umask:630 file:046 dir:147 umask:631 file:046 dir:146 umask:632 file:044 dir:145 umask:633 file:044 dir:144 umask:634 file:042 dir:143 umask:635 file:042 dir:142 umask:636 file:040 dir:141 umask:637 file:040 dir:140 umask:640 file:026 dir:137 umask:641 file:026 dir:136 umask:642 file:024 dir:135 umask:643 file:024 dir:134 umask:644 file:022 dir:133 umask:645 file:022 dir:132 umask:646 file:020 dir:131 umask:647 file:020 dir:130 umask:650 file:026 dir:127 umask:651 file:026 dir:126 umask:652 file:024 dir:125 umask:653 file:024 dir:124 umask:654 file:022 dir:123 umask:655 file:022 dir:122 umask:656 file:020 dir:121 umask:657 file:020 dir:120 umask:660 file:006 dir:117 umask:661 file:006 dir:116 umask:662 file:004 dir:115 umask:663 file:004 dir:114 umask:664 file:002 dir:113 umask:665 file:002 dir:112 umask:666 file:000 dir:111 umask:667 file:000 dir:110 umask:670 file:006 dir:107 umask:671 file:006 dir:106 umask:672 file:004 dir:105 umask:673 file:004 dir:104 umask:674 file:002 dir:103 umask:675 file:002 dir:102 umask:676 file:000 dir:101 umask:677 file:000 dir:100 umask:700 file:066 dir:077 umask:701 file:066 dir:076 umask:702 file:064 dir:075 umask:703 file:064 dir:074 umask:704 file:062 dir:073 umask:705 file:062 dir:072 umask:706 file:060 dir:071 umask:707 file:060 dir:070 umask:710 file:066 dir:067 umask:711 file:066 dir:066 umask:712 file:064 dir:065 umask:713 file:064 dir:064 umask:714 file:062 dir:063 umask:715 file:062 dir:062 umask:716 file:060 dir:061 umask:717 file:060 dir:060 umask:720 file:046 dir:057 umask:721 file:046 dir:056 umask:722 file:044 dir:055 umask:723 file:044 dir:054 umask:724 file:042 dir:053 umask:725 file:042 dir:052 umask:726 file:040 dir:051 umask:727 file:040 dir:050 umask:730 file:046 dir:047 umask:731 file:046 dir:046 umask:732 file:044 dir:045 umask:733 file:044 dir:044 umask:734 file:042 dir:043 umask:735 file:042 dir:042 umask:736 file:040 dir:041 umask:737 file:040 dir:040 umask:740 file:026 dir:037 umask:741 file:026 dir:036 umask:742 file:024 dir:035 umask:743 file:024 dir:034 umask:744 file:022 dir:033 umask:745 file:022 dir:032 umask:746 file:020 dir:031 umask:747 file:020 dir:030 umask:750 file:026 dir:027 umask:751 file:026 dir:026 umask:752 file:024 dir:025 umask:753 file:024 dir:024 umask:754 file:022 dir:023 umask:755 file:022 dir:022 umask:756 file:020 dir:021 umask:757 file:020 dir:020 umask:760 file:006 dir:017 umask:761 file:006 dir:016 umask:762 file:004 dir:015 umask:763 file:004 dir:014 umask:764 file:002 dir:013 umask:765 file:002 dir:012 umask:766 file:000 dir:011 umask:767 file:000 dir:010 umask:770 file:006 dir:007 umask:771 file:006 dir:006 umask:772 file:004 dir:005 umask:773 file:004 dir:004 umask:774 file:002 dir:003 umask:775 file:002 dir:002 umask:776 file:000 dir:001 umask:777 file:000 dir:000
REF:http://oldboy.blog.51cto.com/2561410/1060032
--- --- --- --- From 小小leo 的博客 --- --- --- ---