Using execl to run a Linux command

c, exec, linux, unix

Solution

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]`).

Problem

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); } } ```

Original source