What's the simplest way to copy the unix file permissions of a file and set them to another file? Is there a way to store a file's permissions to a variable and then use that variable to set those permissions to another file?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Sure. Use stat()
and chmod()
(may need root).
#include <sys/stat.h>
struct stat st;
stat("/foo/bar.txt", &st);
chmod("/baz/quirk.jpg", st.st_mode);