unix 'find' command with -prune option ( not to look into all sub directories or not to look into particular sub directory )

1. we can use find command to list the desired pattern/extension files in a directory.

On Unix shell - $ find . -type f -name "*.apk" -o -type f -name "*.sys"

In C/CPP language - sprintf(cmd,"find %s/* -type f -name '*.apk' -o -type f -name '*.sys' ",parent_dir);

2. Using -prune option with find, we can exclude /not to look into particular sub directory

On Unix shell - $ find /home/export/parent_dir/* -name /home/export/child_dir -prune -o -type f -name '*.apk'

and

In C/CPP language - sprintf(cmd,"find %s/* -name %s -prune -o -type f -name '*.apk' ",parent_dir,child_dir);

Here we are excluding child_dir sub directory in listing the files under parent_directory.

3. In some cases we are not sure all sub-directories list and may not sure like somebody might create directories and our above find command fails.

On Unix shell - $find /home/export/parent_dir/* \( ! -name /home/export/parent_dir -prune \) -a \( -type f -name "*.apk" -o -type f -name "*.sys" \) ",parent_dir, parent_dir);

In C/CPP language - sprintf(cmd,"find %s/* \( ! -name %s -prune \) -a \( -type f -name '*.LNK' -o -type f -name '*.conv' \) ",parent_dir,parent_dir);

Don't forget to notice here like we are using find command with -prune with ! mark before -name and mentioning same parent directory only saying include only parent directory not any sub-directory.