How can I use find to traverse a directory, but not recurse into its subdirectories?I tried -prune and it does not work. And there is no -maxdepth option.find /opt/projectname/bin -type f /opt/projectname/bin -prune -o -printfind: missing conjunction/opt/projectname/bin/file_1_is_printed/opt/projectname/bin/file_2_is_printed/opt/projectname/bin/directory_within_bin/some_file_should_not_be_printed/opt/projectname/bin/directory_2_within_bin/some_file_2_should_not_be_printed/usr/bin/find:         find.c $Date: 2011/08/12 15:04:36 $Revision: r11.31/4 PATCH_11.31 (PHCO_42158)         libcpio.c $Date: 2008/05/27 16:08:10 $Revision: r11.31/2 PATCH_11.31 (PHCO_36666)         $Revision: @(#) find R11.31_BL2011_0923_2 PATCH_11.31 PHCO_42158This question is not a repeat question. There is no GNU here. Although the question may be a repeat question, the answers posted on those questions ask installations of GNU tools. Hence if the answers here help solve, this is a unique thread.
find files with path of a directory exclude subdirectories
find
The error missing conjunction is because you repeated the directory name after -type f, and find doesn't know how to parse that.To avoid traversing subdirectories, you need to prune directories, not regular files. However, you must not prune the starting directory, otherwise find will process nothing but it. An easy way of recognizing the starting directory is to arrange for its name to be ..find /opt/projectname/bin/. -name . -o -type d -prune -o -printExplanation:-name . if the name is ., [do nothing]otherwise: -type d if the file is a directory, don't descend into itotherwise: print the path