directory - Finding a text file in Ubuntu directories -
i have program , goal finding text file programs in linux, finds files *.*
. please me find problem of code?
#include<stdio.h> #include<stdlib.h> int main() { char str[256], str2[256], buf[256]; strcpy(str,"find -name "); strcpy(str2,"'*.txt'"); sprintf(buf, "/bin/sh -c %s %s", str,str2); system(buf); return 0; }
find
if called without location search in, 'execution location sensitive' meaning if execute program /
(root) /home/you/myprogram/./executable
, program start searching directories on system. if instead in /home/you/myprogram
, example contained textfile called test.txt
find test.txt
running ./executable
.
i suggest either using program behavior in mind, or introducing parameter find
, specifies location search in. further information see man find
.
Comments
Post a Comment