Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个脚本,并且我想将给定文件的权限应用于另一个文件,因为这两个文件的所有者是相同的。文件可能很大,因此使用移动文件内容
cp dest tmp rm dest cp source dest echo tmp > dest rm tmp
不是一种选择。
你chmod支持这个--reference选项吗?它完全符合您的需要。
chmod
--reference
FILE1="$HOME/.bashrc" FILE2="$HOME/.profile" FPERM=`stat -c "%a" "$FILE1"` chmod $FPERM "$FILE2"
PS。如果还有所有权:
FUID=`stat -c "%U" "$FILE1"` FGID=`stat -c "%G" "$FILE1"` chown $FUID:$FGID "$FILE2"