I need to list all files in the current directory which have a permission of 644 by writing a C language program.
I can not use system() and have to use execl() in order to use system calls.
This a line that I used in my code:
execl("/usr/bin/find", "find . -maxdepth 1 -perm 644", (char *)NULL);
The problem is that the code is searching the whole disk instead of the current directory. Would you help me to fix it please?
...
case 4:
int status;
switch (fork()){
case -1: quit ("fork",1);
case 0:
execl("/usr/bin/find","find","." ,"-maxdepth" ,"1","-perm", "644",(char *)NULL) ;
exit (200);
default:
wait(&status);
exit(0);
}
}
Separate the arguments:
execl("/usr/bin/find", "find", ".", "-maxdepth", "1", "-perm", "644", (char *)NULL);
Your invocation was equivalent to invoking the find program with no arguments (and a very funny argv[0]).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With