前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2.15 更改所有者和所属组chown

2.15 更改所有者和所属组chown

作者头像
运维小白
发布2018-02-06 11:17:16
2K0
发布2018-02-06 11:17:16
举报
文章被收录于专栏:运维小白运维小白

chown命令

chown介绍和例子
  • chown等于change owner 更改文件的所有者和所属组
代码语言:javascript
复制
[root@hf-01 ~]# ls /tmp
aminglinux  amning  mysql.sock  yum.log
[root@hf-01 ~]# ls -l /tmp/yum.log        会看到yum.log的所有者是root
-rw-r--r--. 1 root root 0 10月 26 07:48 /tmp/yum.log
[root@hf-01 ~]# chown aming /tmp/yum.log 
chown: 无效的用户: "aming"             这是因为在/etc/passwd中没有aming这个用户,需要useradd aming即可
[root@hf-01 ~]# chown hanfeng /tmp/yum.log    这时会看到所有者发生了变化,yum.log文件的所有者变化成hanfeng了
[root@hf-01 ~]# !ls
ls -l /tmp/yum.log
-rw-r--r--. 1 hanfeng root 0 10月 26 07:48 /tmp/yum.log
chown的用法
  • chown -R username:group filename
  • chown 【-R】用户名 文件名 /更改所属主
  • chown 【-R】 用户名:组名 文件名 /更改所属主和所属组
代码语言:javascript
复制
[root@hf-01 ~]# !ls
ls -l /tmp/yum.log
-rw-r--r--. 1 hanfeng user1 0 10月 26 07:48 /tmp/yum.log
[root@hf-01 ~]# chown user1:hanfeng /tmp/yum.log
[root@hf-01 ~]# !ls     这里会看到所属主和所属组发生了改变,用户和组中间用:隔开
ls -l /tmp/yum.log
-rw-r--r--. 1 user1 hanfeng 0 10月 26 07:48 /tmp/yum.log
[root@hf-01 ~]# chown -R hanfeng:user1 /tmp/aminglinux/
[root@hf-01 ~]# ls -l /tmp/aminglinux/
总用量 0
drwxr-xr-x. 2 hanfeng user1 18 10月 24 07:21 2
drwxr-xr-x. 4 hanfeng user1 31 10月 25 06:55 aming2
[root@hf-01 ~]# ls -l /tmp/aminglinux/
总用量 0
drwxr-xr-x. 2 hanfeng user1 18 10月 24 07:21 2
drwxr-xr-x. 4 hanfeng user1 31 10月 25 06:55 aming2
[root@hf-01 ~]# ls -ld /tmp/aminglinux/
drwxr-xr-x. 4 hanfeng user1 27 10月 25 07:29 /tmp/aminglinux/
[root@hf-01 ~]# touch /tmp/aminglinux/3.txt
[root@hf-01 ~]# chown -R user1:hanfeng /tmp/aminglinux/
[root@hf-01 ~]# ls -l /tmp/aminglinux/
总用量 0
drwxr-xr-x. 2 user1 hanfeng 18 10月 24 07:21 2
-rw-r--r--. 1 user1 hanfeng  0 10月 26 08:23 3.txt
drwxr-xr-x. 4 user1 hanfeng 31 10月 25 06:55 aming2
[root@hf-01 ~]# ls -ld /tmp/aminglinux/
drwxr-xr-x. 4 user1 hanfeng 39 10月 26 08:23 /tmp/aminglinux/
  • chown 【-R】 :组名 文件名 / 只更改所属组
代码语言:javascript
复制
[root@hf-01 ~]# chown :root /tmp/yum.log
[root@hf-01 ~]# !ls     这里只更改了它的所属组
ls -l /tmp/yum.log
-rw-r--r--. 1 user1 root 0 10月 26 07:48 /tmp/yum.log

-R 只用于目录,作用是级联更改子目录以及子文件。

chgrp

  • chgrp等于change group 更改文件所属的用户组
代码语言:javascript
复制
[root@hf-01 ~]# chgrp user1 /tmp/yum.log
[root@hf-01 ~]# !ls     在之前的所属组是root,现在所属组是user1
ls -l /tmp/yum.log
-rw-r--r--. 1 hanfeng user1 0 10月 26 07:48 /tmp/yum.log
  • chgrp 【-R】 组名 文件名

-R 只用于目录,作用是级联更改子目录以及子文件。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • chown命令
    • chown介绍和例子
      • chown的用法
      • chgrp
      相关产品与服务
      云数据库 SQL Server
      腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档