Linux Chown命令教程

chown command is used to change file and folders user, group, and other ownership. chown is a very useful tool but sometimes becomes very dangerous because it can harm the current owner’s policy.chown mainly changes read, write, and execute the owner according to the given user or group.

chown命令用于更改文件和文件夹的用户,组和其他所有权。 chown是一个非常有用的工具,但有时会非常危险,因为它可能会损害当前所有者的策略。chown主要根据给定的用户或组更改读取,写入和执行所有者。

chown命令语法 (chown Command Syntax)

Syntax of chown is like below.

chown语法如下。

chown OPTIONS USER:GROUP FILE

列出文件和文件夹的用户和组所有者 (List User and Group Owner Of The Files and Folders)

Before starting to change file and folders owner in Linux we should list current owners of the file. We will use ls -l command which will list all files owner users and a group of the current working path.

在Linux中开始更改文件和文件夹所有者之前,我们应该列出文件的当前所有者。 我们将使用ls -l命令,该命令将列出所有文件所有者用户和一组当前工作路径。

$ ls -l
List User and Group Owner Of The Files and Folders
列出文件和文件夹的用户和组所有者

In this example we can see that all files have owner user ismail and owner group ismail .

在此示例中,我们可以看到所有文件都具有所有者用户ismail和所有者组ismail

使用根帐号 (Using Root Account)

While changing permissions and ownership in Linux the most straightforward way is using root account. Root account provides highest privileges so we will have the power to change things.

在Linux中更改权限和所有权时,最直接的方法是使用root帐户。 根帐户具有最高的特权,因此我们将有权更改权限。

更改文件和文件夹的所有者用户 (Change  Owner User Of The File and Folder)

The simplex usage form of chown is changing the owner user of the given file. We will simply specify the owner’s username of the file and file name to do this. In this example, we will change the owner user of a file named acknow.txt to ismail .

chown的单纯形用法形式正在更改给定文件的所有者用户。 我们只需指定文件所有者的用户名和文件名即可。 在此示例中,我们将名为acknow.txt的文件的所有者用户更改为ismail

$ chown ismail acknow.txt

更改文件和文件夹的所有者组名称 (Change Owner Group Name Of The File and Folder)

As we know the files and folders in Linux have owner users and owner groups. We can also change the owner group with chmod command. We will put the new group name after : . In this example, we will change the owner group to ismail .

众所周知,Linux中的文件和文件夹具有所有者用户和所有者组。 我们还可以使用chmod命令更改所有者组。 我们将新的组名放在:。 在此示例中,我们将所有者组更改为ismail

$ chown :ismail acknow.txt

更改用户和所有者组名称 (Change  User and Owner Group Name)

In previous steps, we have changed the user and group ownership of files in separate steps. We can do this user and group ownership change in a single step with : . In this example, we will change user ownership to ahmet and group ownership ismail .

在前面的步骤中,我们在单独的步骤中更改了文件的用户和组所有权。 我们可以通过以下步骤一步一步地完成用户和组所有权的更改: 在此示例中,我们将用户所有权更改为ahmet并将组所有权更改为ismail

$ chown ahmet:ismail acknow.txt

递归更改文件和文件夹的所有权 (Change Files and Folders Ownership Recursively)

Changing the ownership of files one by one is not a practical easy solution if we have 1000 files. Or we may need to change all ownership of folders and subfolders with their file contents. We can use -R for recursive operations.

如果我们有1000个文件,那么一个接一个地更改文件所有权不是一个容易的实用解决方案。 或者,我们可能需要更改文件夹和子文件夹的所有所有权及其文件内容。 我们可以使用-R进行递归操作。

$ chown -R ismail:ismail backup

chown命令详细模式 (chown Command Verbose Mode)

While changing files and folders we may need to print verbose output about changes. We can use -v option in order to change this.

在更改文件和文件夹时,我们可能需要打印有关更改的详细输出。 我们可以使用-v选项来更改它。

$ chown -v -R ismail:ismail *
Verbose Mode
Verbose Mode
详细模式
LEARN MORE  Windows User Management With Net User Like Creating, Deleting, Setting Password
了解更多使用Net用户的Windows用户管理,例如创建,删除,设置密码

翻译自: https://www.poftut.com/linux-chown-command-tutorial-examples-change-ownership-files/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值