linux系統中如何改變文件/目錄的所有者和所屬組


1、測試數據

[root@centos79 test]# ls
[root@centos79 test]# mkdir test1
[root@centos79 test]# touch test1/a.txt
[root@centos79 test]# ll
total 0
drwxr-xr-x. 2 root root 19 Jul 26 10:41 test1
[root@centos79 test]# ll test1/*
-rw-r--r--. 1 root root 0 Jul 26 10:41 test1/a.txt

 

2、修改所有者

[root@centos79 test]# chown liujiaxin01 test1/
[root@centos79 test]# ll
total 0
drwxr-xr-x. 2 liujiaxin01 root 19 Jul 26 10:41 test1

 

3、修改所屬組

[root@centos79 test]# chgrp liujiaxin01 test1/
[root@centos79 test]# ll
total 0
drwxr-xr-x. 2 liujiaxin01 liujiaxin01 19 Jul 26 10:41 test1
[root@centos79 test]# ll test1/*    ## 文件夾下的文件的所有者和所屬組並沒有改變
-rw-r--r--. 1 root root 0 Jul 26 10:41 test1/a.txt

 

4、重新創建測試文件,同時修改所有者和所屬組

[root@centos79 test]# ls
[root@centos79 test]# mkdir test1
[root@centos79 test]# touch test1/a.txt
[root@centos79 test]# ll
total 0
drwxr-xr-x. 2 root root 19 Jul 26 10:45 test1
[root@centos79 test]# ll test1/*
-rw-r--r--. 1 root root 0 Jul 26 10:45 test1/a.txt
[root@centos79 test]# chown liujiaxin01:liujiaxin01 test1/
[root@centos79 test]# ll
total 0
drwxr-xr-x. 2 liujiaxin01 liujiaxin01 19 Jul 26 10:45 test1
[root@centos79 test]# ll test1/*   ## 文件夾內的所有者和所屬組並沒有改變
-rw-r--r--. 1 root root 0 Jul 26 10:45 test1/a.txt

 

5、重新創建測試文件, 遞歸修改文件所有者和所屬組

[root@centos79 test]# ls
[root@centos79 test]# mkdir test
[root@centos79 test]# touch test/a.txt
[root@centos79 test]# ll
total 0
drwxr-xr-x. 2 root root 19 Jul 26 10:47 test
[root@centos79 test]# ll test/*
-rw-r--r--. 1 root root 0 Jul 26 10:47 test/a.txt
[root@centos79 test]# chown -R liujiaxin01:liujiaxin01 test/
[root@centos79 test]# ll
total 0
drwxr-xr-x. 2 liujiaxin01 liujiaxin01 19 Jul 26 10:47 test
[root@centos79 test]# ll test/*
-rw-r--r--. 1 liujiaxin01 liujiaxin01 0 Jul 26 10:47 test/a.txt

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM