命令中的点 (.) 是什么意思?

Wub*_*gee 2 bash

这是我在教程中看到的一个命令:

mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swap
Run Code Online (Sandbox Code Playgroud)

这是什么.意思?

ste*_*ver 9

.在这种情况下是一个弃用形式:,并且是新的所有者和组之间的隔板。

来自info chown

   Some older scripts may still use ‘.’ in place of the ‘:’ separator.
POSIX 1003.1-2001 (*note Standards conformance::) does not require
support for that, but for backward compatibility GNU ‘chown’ supports
‘.’ so long as no ambiguity results.  New scripts should avoid the use
of ‘.’ because it is not portable, and because it has undesirable
results if the entire OWNER‘.’GROUP happens to identify a user whose
name contains ‘.’.
Run Code Online (Sandbox Code Playgroud)

所以在这种情况下,它与 相同chown root: /swap,这反过来意味着

OWNER:
     If a colon but no group name follows OWNER, that user is made the
     owner of the files and the group of the files is changed to OWNER’s
     login group.
Run Code Online (Sandbox Code Playgroud)

由于 root 的登录组是root,它相当于chown root:root /swap

  • 呸!我只是在写我的答案,你打败了我。+1 =) (3认同)

Ter*_*nce 5

它是一个缩短的版本

sudo chown root:root /swap
Run Code Online (Sandbox Code Playgroud)

因为它将组设置为与用户名相同。

尝试创建一个文件夹,然后以同样的方式将所有权设置为 root,然后在完成后,尝试将所有权设置为您的用户名。

sudo chown $USER. folder/
Run Code Online (Sandbox Code Playgroud)

希望这有帮助!