Linux chfn 命令初学者教程(6 个示例)Linux chfn 命令初学者教程(6 个示例)Linux chfn 命令初学者教程(6 个示例)Linux chfn 命令初学者教程(6 个示例)
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

Linux chfn 命令初学者教程(6 个示例)

在此页

  1. Linux chfn 命令
  2. Q1。如何使用 chfn 更改用户全名?
  3. Q2。如何使用 chfn 更改家庭电话号码?
  4. Q3。如何使用 chfn 更改用户房间号?
  5. Q4。如何使用 chfn 更改用户的工作电话号码?
  6. Q5。如何验证通过 chfn 所做的更改?
  7. Q6。如何一次更改所有信息?
  8. 结论

Linux 中的用户有很多与之相关的信息,包括家庭和办公室电话号码、办公室房间号码等等。我们通常在创建用户时跳过填写此信息(因为它都是可选的)。但是你知道有一个命令可以让你调整所有这些信息吗?

在本教程中,我们将使用一些易于理解的示例来讨论 chfn 命令的基础知识。但在此之前,值得一提的是,本文中的所有示例都已在 Ubuntu 18.04LTS 机器上进行了测试。

Linux chfn 命令

Linux 中的 chfn 命令基本上可以让您轻松更改用户的全名以及相关信息。以下是它的语法:

chfn [options] [LOGIN]

这是手册页中关于它的内容:

 The chfn command changes user fullname, office room number, office
phone number, and home phone number information for a user's account.
This information is typically printed by finger(1) and similar
programs. A normal user may only change the fields for her own account,
subject to the restrictions in /etc/login.defs. (The default
configuration is to prevent users from changing their fullname.) The
superuser may change any field for any account. Additionally, only the
superuser may use the -o option to change the undefined portions of the
GECOS field.

These fields must not contain any colons. Except for the other field,
they should not contain any comma or equal sign. It is also recommended
to avoid non-US-ASCII characters, but this is only enforced for the
phone numbers. The other field is used to store accounting information
used by other applications.

以下是一些问答式示例,可让您了解 chfn 命令的实际工作原理。

Q1。如何使用 chfn 更改用户全名?

这可以通过以下方式使用 -f 命令行选项来完成:

sudo chfn -f HimanshuArora himanshu

请注意,himanshu 是全名更改为 HimanshuArora 的 Linux 用户。

Q2。如何使用 chfn 更改家庭电话号码?

要更改家庭电话号码,请使用 -h 命令行选项。

sudo chfn -h 0172-666666 himanshu

Q3.如何使用 chfn 更改用户房间号?

这可以使用 -r 命令行选项来完成。

sudo chfn -r 12 himanshu

Q4.如何使用 chfn 更改用户的工作电话号码?

要更改工作电话号码,请使用 -w 命令行选项。

sudo chfn -w 0173-222222 himanshu

Q5.如何验证通过 chfn 所做的更改?

要验证您通过 chfn 所做的所有更改是否已成功保存,请使用 finger 命令。例如,在我执行所有前面部分的命令后,这个命令在我的系统上显示的是什么。

所以你可以看到通过 chfn 所做的所有更改都已保存。

请注意,如果您的系统上未安装 finger,请使用以下命令安装它:

sudo apt-get install finger

Q6.如何一次更改所有信息?

如果您想一次性更改所有与用户相关的信息,请使用没有任何选项的 chfn 命令(指定用户名,以防您想要为当前登录用户以外的用户执行此操作)。

chfn

结论

无论您只是想要更改关联信息的用户,还是想要更改多个用户信息的系统管理员,chfn 命令都可以为您服务。我们在这里讨论了大多数命令行选项。要了解更多信息,请访问工具手册页。

©2015-2025 艾丽卡 support@alaica.com