linux命令chown修改文件所有权

本文介绍了如何使用 chown 和 chgrp 命令来更改文件的所有者和组所有权。详细解释了命令的语法和常见选项,如递归更改 (-R) 的用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  Changing User Ownership  

      To apply appropriate permissions, the first thing to consider is ownership. To do this, there is the  chown  command. The syntax of this command is not hard to understand:    
■    chown who what    
       For instance, the following command changees ownership for the file account to user linda:    
■    chown linda account    
       The  chown  command has a few options, of which one is particularly useful:   -R . You might guess what it does, because this option is available for many other commands as well. It allows you to set ownership recursively, which allows you to set ownership of the current directory and everything below. The following command changes ownership for the directory /home and everything beneath it to user linda:    
■    chown -R linda /home/linda

  Changing Group Ownership  

        There are actually two ways to change group ownership. You can do it using  chown , but there is also a specific command with the name  chgrp  that does the job. If you want to use the  chown  command, use a  .  or  :  in front of the group name. The following changes the group owner of directory /home/account to the group account:    
chown .account /home/account  

       You can use  chown  to change user and/or group ownership in a number of ways, an overview of which follows:    
■   chown lisa myfile     Sets user lisa as the owner of myfile    
■    chown lisa.sales myfile     Sets user lisa as user owner and group sales as group owner of myfile    
■    chown lisa:sales myfile     Sets user lisa as user owner and group sales as group owner of myfile    
■    chown .sales myfile     Sets group sales as group owner of myfile without changing the user owner    
■    chown :sales myfile     Sets group sales as group owner of myfile without changing the user owner    
      You can also use the  chgrp  command to change group ownership. Consider the following example, where you can use  chgrp  to set group ownership for the directory / home/account to the group account:    
■    chgrp account /home/account    
      As is the case for  chown , you can use the option  -R  with  chgrp  as well to change group ownership recursively.  

转载于:https://www.cnblogs.com/rusking/p/5611535.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值