Prevent Unix "find" command from recursing into matched directories

2015-03-18T17:18:28

Consider the following command to find and update all git repos in a particular directory:

find . -type d -name .git | while read src_dir; do
    my_git_update "${1}";
done;

Assume that a repo cannot contain other repos, so there is no point in going deeper into that directory. I am not using sub-modules and such, so nested cases don't count for this question. So in general...

Is there a way to tell find to stop recursing into a directory once a match is found?

Based on my searches, the answer may lie with -prune, but I can't figure out exactly how to use it in my case.


Unix 'find' without descending into matched directories is not a duplicate, despite the title. It focuses on deletion of sub-directories - that solution is not applicable here.

Copyright License:
Author:「metacubed」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/29118044/prevent-unix-find-command-from-recursing-into-matched-directories

About “Prevent Unix "find" command from recursing into matched directories” questions

I have a small routine where I apply some regex over a file and write the whole content to a new file. perl -p -e "myRegexReplace" %INPUT% >%OUTPUT% The script is executed on a windows machine...
[UNIX] Assume that there exists a user X (i.e. not a superuser), which belongs to a group G. This user X creates a file F in a directory, with permissions "rw-rw----". Is there a way to prevent del...
Is there any way that we can prevent accessing Unix files through JVM ( any code running in application server JVM). One solution is to do it at the unix user level. Is there any other way we confi...
For example, I mostly program in PHP. What can I do today to prevent my program from exploding in 2038 due to unix time stamp running out? I would love to see some specific algorithms, functions or
Does anyone know the buffering characteristics of Unix sockets when sending small chunks of data (a few bytes)? When I am using TCP sockets, I can disable the Nagle algorithm to prevent latency in ...
I have a Bash script that I run inside of iTerm 2.1.3 on a Mac. I like to use color codes to change the color of the script's output if there's an error: #!/usr/bin/env bash database=mydb RED='\...
Is it possible on Linux or MacOSX to prevent a Unix domain socket file (e.g. in /tmp) that is currently bound from being deleted? I want a mode 0777 socket that users can connect to but that users ...
I have a python script that I'd like to supply with an argument (usually) containing wildcards, referring to a series of files that I'd like to do stuff with. Example here: #!/usr/bin/env python ...
I have simple HTTP server in Ocaml with Cohttp and Lwt. When I run wrk the application crashes around 50% of the time as soon as wrk finishes. I imagine the crash is triggered by the unexpected tea...
How to configure mongo DB to not to listen on any port, but only on unix domain socket? Since my app and DB will run on same server, the two will communicate only via Unix domain sockets. To preve...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.