用最近学的半吊子 awk 试着做了一条很丑的 one-liner 解决微信收到的 Word 文件都是只读的问题:

find ~/Library/Containers/com.tencent.xinWeChat -name '*.doc*' -print0 | xargs -0 stat -f "%a%t%N" | sort -r | head -10 | awk 'BEGIN { FS="\t"; } { printf "\"%s\" ", $2 }' | xargs chmod 644

解释:find 找到微信目录下面所有 doc 和 docx 文件;传给 xargsstat 输出找到文件的时间戳和路径;传给 sorthead 按时间戳逆序排出前十个(应付同时收到一堆文件的情况);传给 awk 单挑出来文件路径并且裹在引号里(防止文件名有空格);最后再传给 xargschmod 把权限改成 644(rw-r--r--)

Please be advised that this post was written or last updated a while ago and may therefore contain outdated information or opinions I no longer hold.
请知悉本文自写作或上次更新已届相当时限,或包含过时信息及观点。