![如何更改自己创建的文件的默认权限?](https://linux22.com/image/557286/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9%E8%87%AA%E5%B7%B1%E5%88%9B%E5%BB%BA%E7%9A%84%E6%96%87%E4%BB%B6%E7%9A%84%E9%BB%98%E8%AE%A4%E6%9D%83%E9%99%90%EF%BC%9F.png)
[root@ test_project]$ touch test.txt
[root@ test_project]$ ll test.txt
-rw-rw-r-- 1 root root 0 2011-08-03 13:57 test.txt
目前看来是这样的664
,我该如何改变它700
?
答案1
您可以使用umask命令来更改文件创建掩码。但这只会屏蔽位。如果创建文件的应用程序不请求设置位,则 umask 将不会设置它。然后umask 077
通常会创建文件600
和目录700
您可以在 $HOME/.profile 中设置默认的 umask
答案2
你想使用umask
sente@oslo: $ umask
0022
sente@oslo: $ umask -S
u=rwx,g=rx,o=rx
sente@oslo: $ touch foo
sente@oslo: $ ls -l foo
-rw-r--r-- 1 sente pg2662512 0 2011-08-02 23:13 foo
sente@oslo: $ umask -S u=rwx,g=,o=
u=rwx,g=,o=
sente@oslo: $ touch bar
sente@oslo: $ ls -l bar
-rw------- 1 sente pg2662512 0 2011-08-02 23:13 bar
我认为您仍然需要 chmod u+x。
sente@oslo: $ help umask
:
umask: umask [-p] [-S] [mode]
The user file-creation mask is set to MODE. If MODE is omitted, or if
`-S' is supplied, the current value of the mask is printed. The `-S'
option makes the output symbolic; otherwise an octal number is output.
If `-p' is supplied, and MODE is omitted, the output is in a form
that may be used as input. If MODE begins with a digit, it is
interpreted as an octal number, otherwise it is a symbolic mode string
like that accepted by chmod(1).