useradd/usermod 不接受 -c

Num*_*945 3 command-line users adduser

当我运行以下命令时:

sudo usermod –c "Richard Tracy" dtracy 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -v, --add-subuids FIRST-LAST  add range of subordinate uids
  -V, --del-subuids FIRST-LAST  remove range of subordinate uids
  -w, --add-subgids FIRST-LAST  add range of subordinate gids
  -W, --del-subgids FIRST-LAST  remove range of subordinate gids
  -Z, --selinux-user SEUSER     new SELinux user mapping for the user account
Run Code Online (Sandbox Code Playgroud)

它声明我们可以使用-coption ,那么为什么它不接受我的命令呢?我还看到,在创建用户并-c输入useradd命令时,我仍然收到上述消息并且操作失败。

要重现上述错误,只需运行sudo useradd dtracydtracy使用默认值创建一个用户,然后尝试通过上述usermod命令进行修改。

Eli*_*gan 6

您运行的命令包含–c,它是一个短划线,后跟一个c尽管像这样的选项参数-c通常非正式地发音为“dash c”,但它们实际上必须以 ASCII 连字符开头。这与 ASCII 减号字符相同(此字符的一个名称是“连字符减号”),但与其他 Unicode 破折号字符(如短划线和长破折号)不同。

命令没有赋予这些破折号任何特殊含义,因此当-c参数指定短选项时c–c参数根本不指定任何选项。您实际上usermod使用三个非选项参数运行,这不是它接受的语法之一,因此它打印了帮助消息。

人们最终在命令中输入破折号而不是连字符的原因是——好吧,没有人这样做。相反,一些网站将连字符转换为短划线。因此,当从此类网站的页面复制命令并将其粘贴到终端时,它错误地包含破折号而不是连字符。如果使用 LibreOffice 之类的程序来存储命令列表(并且没有关闭自动格式化),也会发生这种情况。

在实践中经常从这种被破坏的文本中出现的类似问题包括在标点符号附近插入额外的空格(在rm -r命令中非常糟糕!),用弯引号替换直引号,以及<字符和匹配>字符之间的文本消失。

您要运行的命令,sudo usermod -c "Richard Tracy" dtracy,工作正常。