4

如何复制文件的权限和所属关系

 2 years ago
source link: https://www.lujun9972.win/blog/2018/02/28/%E5%A6%82%E4%BD%95%E5%A4%8D%E5%88%B6%E6%96%87%E4%BB%B6%E7%9A%84%E6%9D%83%E9%99%90%E5%92%8C%E6%89%80%E5%B1%9E%E5%85%B3%E7%B3%BB/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何复制文件的权限和所属关系

有的时候可能需要把一些文件的所属关系和权限改成跟某个特定文件一样。

我之前一般的做法就是先

ls -l $reference_file

查看这个特定文件的权限和所属关系后再用 chownchmod 来进行修改。

chown XXX:XXX file
chmod XXX file

不过,偶然一次发现,其实 chownchmod 本身已经提供了一个 --reference 的选项可以根据引用文件来修改文件的权限和所属关系。

其语法为:

chmod --reference=reference_file file1 file2...
chown --reference=reference_file file1 file2...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK