[root@localhost Demo1]# ls -l /var/log/squid/
总用量 8
-rw-r-----. 1 squid squid 0 9月 29 08:52 access.log
-rw-r-----. 1 squid squid 6197 9月 30 10:37 cache.log
我想将/var/log/squid/目录下所有文件权限循环输出,就是只输出“-rw-r-----“这些内容,请问怎么写?
[root@localhost Demo1]# ls -l /var/log/squid/
总用量 8
-rw-r-----. 1 squid squid 0 9月 29 08:52 access.log
-rw-r-----. 1 squid squid 6197 9月 30 10:37 cache.log
我想将/var/log/squid/目录下所有文件权限循环输出,就是只输出“-rw-r-----“这些内容,请问怎么写?
``` if(st.st_mode & S_IRUSR) printf("r");else printf("-"); //所属用户权限
if(st.st_mode & S_IWUSR) printf("w");else printf("-");
if(st.st_mode & S_IXUSR) printf("x");else printf("-");
if(st.st_mode & S_IRGRP) printf("r");else printf("-"); //所属组权限
if(st.st_mode & S_IWGRP) printf("w");else printf("-");
if(st.st_mode & S_IXGRP) printf("x");else printf("-");
if(st.st_mode & S_IROTH) printf("r");else printf("-"); //其他用户权限
if(st.st_mode & S_IWOTH) printf("w");else printf("-");
if(st.st_mode & S_IXOTH) printf("x");else printf("-");