博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
改变文件属主和属组 2012-02-09
阅读量:6175 次
发布时间:2019-06-21

本文共 3026 字,大约阅读时间需要 10 分钟。

  hot3.png

< chown - change the owner of a file >
You can change the owner and group of a file or a directory with the chown command. Please, keep in mind you can do this only if you are the root user or the owner of the file.
Set the file's owner:
$ chown username somefile
After giving this command, the new owner of a file called somefile will be the user username. The file's group owner will not change. Instead of a user name, you can also give the user's numeric ID here if you want.
You can also set the file's group at the same time. If the user name is followed by a colon and a group name, the file's group will be changed as well.
$ chown username:usergroup somefile
After giving this command, somefile's new owner would be user username and the group usergroup.
You can set the owner of a directory exactly the same way you set the owner of a file:
$ chown username somedir
Note that after giving this command, only the owner of the directory will change. The owner of the files inside of the directory won't change.
In order to set the ownership of a directory and all the files in that directory, you'll need the -R option:
$ chown -R username somedir
Here, R stands for recursive because this command will recursively change the ownership of directories and their contents. After issuing this example command, the user username will be the owner of the directory somedir, as well as every file in that directory.
Tell what happens:
$ chown -v username somefile
changed ownership of 'somefile' to username
Here, v stands for verbose. If you use the -v option, chown will list what it did (or didn't do) to the file.
The verbose mode is especially useful if you change the ownership of several files at once. For example, this could happen when you do it recursively:
$ chown -Rv username somedir
changed ownership of 'somedir/' to username
changed ownership of 'somedir/boringfile' to username
changed ownership of 'somedir/somefile' to username
As you can see, chown nicely reports to you what it did to each file.
< chgrp - change the group ownership of a file >
In addition to chown, you can also use the chgrp command to change the group of a file or a directory. You must, again, be either the root user or the owner of the file in order to change the group ownership.
chgrp works pretty much the same way as chown does, except it changes the file's user group instead of the owner, of course.
$ chgrp usergroup somefile
After issuing this command, the file somefile will be owned by a user group usergroup. Although the file's group has changed to usergroup, the file's owner will still be the same.
The options of using chgrp are the same as using chown. So, for example, the -R and -v options will work with it just like they worked with chown:
$ chgrp -Rv usergroup somedir
changed group of 'somedir/' to usergroup
changed group of 'somedir/boringfile' to usergroup
changed group of 'somedir/somefile' to usergroup
chown nicely reports to you what it did to each file.

转载于:https://my.oschina.net/qibing/blog/61517

你可能感兴趣的文章
poj3078
查看>>
什么是环境变量?
查看>>
帝国cms后台集成ueditor编辑器
查看>>
WPF绑定各种数据源之xml数据源
查看>>
通过java程序调用ant build.xml配置文件中指定的target
查看>>
判断 ACdream 1202 Integer in C++
查看>>
水题 ZOJ 3875 Lunch Time
查看>>
各种排序算法的分析及java实现
查看>>
JAVA/GUI程序之记事本
查看>>
[ZT]Mac下安装Eclipse和Tomcat等
查看>>
BZOJ2595:[Wc2008]游览计划——题解(插头dp)
查看>>
Guava学习笔记:Google Guava 类库简介
查看>>
90.bower解决js的依赖管理
查看>>
安装图形界面
查看>>
web容器启动顺序
查看>>
Oracle EBS-SQL (PO-12):检查期间请购单的下达记录数.sql
查看>>
用jvm指令分析String 常量池
查看>>
django-allauth 使用
查看>>
输入输出
查看>>
实用技巧:Google 搜索打不开的解决方法【图文教程◆一劳永逸】
查看>>