linux仿寫chmod命令
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc,char **argv)
{
int mode;
int mode_u;
int mode_g;
int mode_o;
char *path;
if(argc<3)
{
printf("%s <mode num> <target file>\n",argv[0]);;
exit(0);
}
mode = atoi(argv[1]);
if(mode>777||mode<0)
{
printf("mode num error");
exit(0);
}
mode_u = mode/100;
mode_g = (mode- mode_u*100)/10;
mode_o = mode -mode_u*100-mode_g*10;
mode = mode_u*8*8+mode_g*8+mode_o;
path = argv[2];
if(chmod(path,mode)==-1)
{
perror("chmod error");
exit(1);
}
return 0;
}
相關(guān)文章
shell向文件中添加新內(nèi)容的實(shí)現(xiàn)方法
Shell腳本是一種為shell編寫的腳本程序,下面這篇文章主要給大家介紹了關(guān)于shell向文件中添加新內(nèi)容的實(shí)現(xiàn)方法,需要的朋友可以參考下2023-06-06ssh,scp自動(dòng)登陸的實(shí)現(xiàn)方法
這篇文章主要介紹ssh,scp自動(dòng)登陸的實(shí)現(xiàn)方法,需要的朋友可以參考下2013-02-02Linux下科學(xué)計(jì)數(shù)法(e)轉(zhuǎn)化為數(shù)字的方法
這篇文章主要介紹了Linux下科學(xué)計(jì)數(shù)法(e)轉(zhuǎn)化為數(shù)字的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05