版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/heiyouhei123/article/details/82683052
0. linux文件权限背景知识
我们通过ls -l
可以看到linux系统中文件的相关权限,比如:
下面是对文件权限信息的截图:
上面的权限对于文件和目录的含义是不同的,具体区分如下:
Access | Meaning for a file | Meaning for a directory |
---|---|---|
r | View file contents. | Search directory contents (e.g., use ls). |
w | Alter file contents. | Alter directory contents (e.g., delete or rename files). |
x | Run executable file. | Make it your current directory (cd to it) |
1. 修改文件owner
通常情况下只有root才有相关的权限进行操作
命令格式: chown newOwnerName/newOwnerId fileName
示例:
[root@localhost mongo]# pwd
/home/mongo
[root@localhost mongo]# ll
total 0
-rw-rw-r--. 1 mongo mongo 0 Sep 12 21:20 1.txt
[root@localhost mongo]# chown mysql 1.txt
[root@localhost mongo]# ll
total 0
-rw-rw-r--. 1 mysql mongo 0 Sep 12 21:20 1.txt
[root@localhost mongo]#
如果想要将某个目录下的所有文件都进行修改,可以在命令行上添加-R
参数.
命令格式: chown -R newOwnerName/newOwnerId dirName
同时,chown命令也可以同时修改文件的组信息,命令格式如下:
chown newOwnerName:newOwnerGroupName fileName
2. 修改文件所在的组
通常拥有修改文件组操作权限的可能的用户是:
1) root
2) 文件的拥有者同时文件拥有者也是新的组里面的成员(注意: 这里没有要求文件拥有者在当前文件所在的组内)
命令格式: chgrp newGroupName/newGroupId fileName
同chown命令一样,你也可以通过添加-R
命令来递归的修改某个目录下的所有文件的组信息
3. 查看文件的类型
file yourFileName