Skip to main content
Fix to only filter files.
Source Link
Stephen Kitt
  • 480.9k
  • 59
  • 1.2k
  • 1.4k

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -ef {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -ef {}/.git ] \; -prune prunes directories containing a file named .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -ef {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that toThis also works when run this on a directory other than ., you’ll need to change bothby changing the find start path, and the first test:

find /some/other/path -type d \( \( ! -path /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

or use -mindepth if your find supports that:

find /some/other/path -mindepth 1 -type d \( \( -exec [ -ef {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -e {}/.git ] \; -prune prunes directories containing .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that to run this on a directory other than ., you’ll need to change both the find start path, and the first test:

find /some/other/path -type d \( \( ! -path /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

or use -mindepth if your find supports that:

find /some/other/path -mindepth 1 -type d \( \( -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

find actions are also tests, so you can add tests using -exec:

find . \( -exec [ -f {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • -exec [ -f {}/.git ] \; -prune prunes directories containing a file named .git
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( -exec [ -f {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

This also works when run this on a directory other than ., by changing the find start path:

find /some/other/path -type d \( \( -exec [ -f {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)
Add -mindepth variant.
Source Link
Stephen Kitt
  • 480.9k
  • 59
  • 1.2k
  • 1.4k

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -e {}/.git ] \; -prune prunes directories containing .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that to run this on a directory other than ., you’ll need to change both the find start path, and the first test:

find /some/other/path -type d \( \( ! -path /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

or use -mindepth if your find supports that:

find /some/other/path -mindepth 1 -type d \( \( -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -e {}/.git ] \; -prune prunes directories containing .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that to run this on a directory other than ., you’ll need to change both the find start path, and the first test:

find /some/other/path -type d \( \( ! -path /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -e {}/.git ] \; -prune prunes directories containing .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that to run this on a directory other than ., you’ll need to change both the find start path, and the first test:

find /some/other/path -type d \( \( ! -path /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

or use -mindepth if your find supports that:

find /some/other/path -mindepth 1 -type d \( \( -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)
Fix the last variant, thanks RoVo!
Source Link
Stephen Kitt
  • 480.9k
  • 59
  • 1.2k
  • 1.4k

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -e {}/.git ] \; -prune prunes directories containing .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that to run this on a directory other than ., you’ll need to change both the find start path, and the name given to the first test:

find /some/other/path -type d \( \( ! -namepath /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

(-name path must correspond to the last component in the start path).

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -e {}/.git ] \; -prune prunes directories containing .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that to run this on a directory other than ., you’ll need to change both the find start path, and the name given to the first test:

find /some/other/path -type d \( \( ! -name path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

(-name path must correspond to the last component in the start path).

find actions are also tests, so you can add tests using -exec:

find . \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print

This applies three sets of actions:

  • ! -name . -exec [ -e {}/.git ] \; -prune prunes directories containing .git, except on . (so that you can run the command from the root of a git repository without excluding the whole repository)
  • -name .git -prune prunes directories named .git (so the command doesn’t search inside the main .git directory of a repository)
  • -print prints anything which isn’t caught by the above.

To only match directories, add -type d, either just before -print, or (to save time processing files):

find . -type d \( \( ! -name . -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)

Note that to run this on a directory other than ., you’ll need to change both the find start path, and the first test:

find /some/other/path -type d \( \( ! -path /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)
Explain how to run this elsewhere.
Source Link
Stephen Kitt
  • 480.9k
  • 59
  • 1.2k
  • 1.4k
Loading
Source Link
Stephen Kitt
  • 480.9k
  • 59
  • 1.2k
  • 1.4k
Loading