I'm trying to run a find command for all JavaScript files, but how do I exclude a specific directory?

Here is the find code we're using.

for file in $(find . -name '*.js'); do java -jar config/yuicompressor-2.4.2.jar --type js $file -o $file; done
share|improve this question
5  
What's the directory you need to exclude? – The Archetypal Paul Nov 17 '10 at 23:00
5  
It's better to use find ... | while read -r file .... Also, it's better to accept and upvote answers. – Dennis Williamson Nov 17 '10 at 23:26
    
while read is slow, for in is faster – mpapis Nov 18 '10 at 17:08
12  
@mpapis while read correctly handles full lines with whitespace. – Jean-Philippe Pellet Aug 16 '12 at 10:44
1  
Just run this in a folder with files with spaces in their names: for file in $(find .); do echo "$file"; done. Names with spaces are split, which we don't want. – Jean-Philippe Pellet Dec 2 '15 at 10:09

29 Answers 29

up vote 584 down vote accepted

Use the prune switch, for example if you want to exclude the misc directory just add a -path ./misc -prune -o to your find command:

find . -path ./misc -prune -o -name '*.txt' -print

Here is an example with multiple directories:

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

Here we exclude dir1, dir2 and dir3, since in find expressions it is an action, that acts on the criteria -path dir1 -o -path dir2 -o -path dir3 (if dir1 or dir2 or dir3), ANDed with type -d. Further action is -o print, just print.

share|improve this answer
15  
shouldn't find . -name ./misc ... be find . -path ./misc ...? – Dennis Hodapp Apr 6 '12 at 3:18
45  
Hmm. This doesn't work for me either as it will include the ignored directory "./misc" in the output. – Theuni Dec 12 '12 at 8:52
35  
@Theuni It probably didn't work for you because you didn't add a -print (or any other action) explicitly after -name. In that case, both "sides" of -o end up printing, whereas if you use -print, only that side prints. – Daniel C. Sobral May 16 '13 at 19:06
18  
Didn't work but stackoverflow.com/a/15736463/434423 did the trick. – Jean-Pierre Chauvel Jul 26 '13 at 18:02
2  
For those having problems with this command, try moving the -type d to after the -prune: find . \( -path ./path1 -o -path ./path2 \) -prune -o -type d -print – dohpaz42 Jul 30 '15 at 2:24

If -prune doesn't work for you, this will:

find -name "*.js" -not -path "./directory/*"
share|improve this answer
60  
One of the comments in the accepted answer points out the problem. -prune does not exclude the directory itself, it exclude its content, which means you are going to get an unwanted line in the output with the excluded directory. – GetFree Apr 1 '13 at 8:20
50  
Great answer. I'd add to this that you can exclude a directory at ANY level by changing the first . to *. so find -name "*.js" -not -path "*/omitme/*" would omit files from a directory named "omitme" at any level of depth. – DeeDee May 1 '13 at 2:51
59  
It still traverses all of the unwanted directory, though. I'm adding my own answer. :-) – Daniel C. Sobral May 16 '13 at 18:52
10  
Note, however, that the prune option only doesn't work if you don't use -print explicitly. – Daniel C. Sobral May 16 '13 at 19:07
34  
It would be better to say "This is an alternative to using -prune". The answers suggesting -prune are clearly not wrong, they just aren't the way you would do it. – Jimbo Aug 16 '13 at 8:27

I find the following easier to reason about than other proposed solutions:

find build -not \( -path build/external -prune \) -name \*.js

This comes from an actual use case, where I needed to call yui-compressor on some files generated by wintersmith, but leave out other files that need to be sent as-is.

Inside \( and \) is an expression that will match exactly build/external, and will, on success, avoid traversing anything below. This is then grouped as a single expression with the escaped parenthesis, and prefixed with -not which will make find skip anything that was matched by that expression.

One might ask if adding -not will not make all other files hidden by -prune reappear, and the answer is no. The way -prune works is that anything that, once it is reached, the files below that directory are permanently ignored.

That is also easy to expand to add additional exclusions. For example:

find build -not \( -path build/external -prune \) -not \( -path build/blog -prune \) -name \*.js
share|improve this answer
20  
Outstanding answer, thank you. This works and is scalable (readable) for multiple exclusions. You are a gentlemen and a scholar sir. Thank you for the example for multiple exclusions – Freedom_Ben Aug 16 '13 at 16:38
6  
This does not work if I want to use -delete switch: find . -not \( -path ./CVS -prune \) -type f -mtime +100 -delete find: The -delete action atomatically turns on -depth, but -prune does nothing when -depth is in effect. If you want to carry on anyway, just explicitly use the -depth option. – Jānis Elmeris Dec 14 '13 at 9:12
14  
@Janis You can use -exec rm -rf {} \; instead of -delete. – Daniel C. Sobral Dec 15 '13 at 21:14
8  
By examining the output of find, this is obvious really, but it tripped me up. If you are searching in the current directory (by specifying . as the search path, or not specifying one at all), you most likely want your pattern after -path to start with ./, e.g: find -not \( -path ./.git -prune \) -type f. – Zantier Oct 9 '14 at 10:10
2  
A more precise (and POSIX compatible) variation of this method: find searchdir \! \( -type d \( -path './excludedir/*' -o -path './excludedir2/*' -o -path './excludedir3/*' \) -prune \) followed by any conditions that should match what you are looking for. – Walf May 26 '17 at 4:17

There is clearly some confusion here as to what the preferred syntax for skipping a directory should be.

GNU Opinion

To ignore a directory and the files under it, use -prune

From the GNU find man page

Reasoning

-prune stops find from descending into a directory. Just specifying -not -path will still descend into the skipped directory, but -not -path will be false whenever find tests each file.

Issues with -prune

-prune does what it's intended to, but are still some things you have to take care of when using it.

  1. find prints the pruned directory.

    • TRUE That's intended behavior, it just doesn't descend into it. To avoid printing the directory altogether, use a syntax that logically omits it.
  2. -prune only works with -print and no other actions.

    • NOT TRUE. -prune works with any action except -delete. Why doesn't it work with delete? For -delete to work, find needs to traverse the directory in DFS order, since -deletewill first delete the leaves, then the parents of the leaves, etc... But for specifying -prune to make sense, find needs to hit a directory and stop descending it, which clearly makes no sense with -depth or -delete on.

Performance

I set up a simple test of the three top upvoted answers on this question (replaced -print with -exec bash -c 'echo $0' {} \; to show another action example). Results are below

----------------------------------------------
# of files/dirs in level one directories
.performance_test/prune_me     702702    
.performance_test/other        2         
----------------------------------------------

> find ".performance_test" -path ".performance_test/prune_me" -prune -o -exec bash -c 'echo "$0"' {} \;
.performance_test
.performance_test/other
.performance_test/other/foo
  [# of files] 3 [Runtime(ns)] 23513814

> find ".performance_test" -not \( -path ".performance_test/prune_me" -prune \) -exec bash -c 'echo "$0"' {} \;
.performance_test
.performance_test/other
.performance_test/other/foo
  [# of files] 3 [Runtime(ns)] 10670141

> find ".performance_test" -not -path ".performance_test/prune_me*" -exec bash -c 'echo "$0"' {} \;
.performance_test
.performance_test/other
.performance_test/other/foo
  [# of files] 3 [Runtime(ns)] 864843145

Conclusion

Both f10bit's syntax and Daniel C. Sobral's syntax took 10-25ms to run on average. GetFree's syntax, which doesn't use -prune, took 865ms. So, yes this is a rather extreme example, but if you care about run time and are doing anything remotely intensive you should use -prune.

Note Daniel C. Sobral's syntax performed the better of the two -prune syntaxes; but, I strongly suspect this is the result of some caching as switching the order in which the two ran resulted in the opposite result, while the non-prune version was always slowest.

Test Script

#!/bin/bash

dir='.performance_test'

setup() {
  mkdir "$dir" || exit 1
  mkdir -p "$dir/prune_me/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/w/x/y/z" \
    "$dir/other"

  find "$dir/prune_me" -depth -type d -exec mkdir '{}'/{A..Z} \;
  find "$dir/prune_me" -type d -exec touch '{}'/{1..1000} \;
  touch "$dir/other/foo"
}

cleanup() {
  rm -rf "$dir"
}

stats() {
  for file in "$dir"/*; do
    if [[ -d "$file" ]]; then
      count=$(find "$file" | wc -l)
      printf "%-30s %-10s\n" "$file" "$count"
    fi
  done
}

name1() {
  find "$dir" -path "$dir/prune_me" -prune -o -exec bash -c 'echo "$0"'  {} \;
}

name2() {
  find "$dir" -not \( -path "$dir/prune_me" -prune \) -exec bash -c 'echo "$0"' {} \;
}

name3() {
  find "$dir" -not -path "$dir/prune_me*" -exec bash -c 'echo "$0"' {} \;
}

printf "Setting up test files...\n\n"
setup
echo "----------------------------------------------"
echo "# of files/dirs in level one directories"
stats | sort -k 2 -n -r
echo "----------------------------------------------"

printf "\nRunning performance test...\n\n"

echo \> find \""$dir"\" -path \""$dir/prune_me"\" -prune -o -exec bash -c \'echo \"\$0\"\'  {} \\\;
name1
s=$(date +%s%N)
name1_num=$(name1 | wc -l)
e=$(date +%s%N)
name1_perf=$((e-s))
printf "  [# of files] $name1_num [Runtime(ns)] $name1_perf\n\n"

echo \> find \""$dir"\" -not \\\( -path \""$dir/prune_me"\" -prune \\\) -exec bash -c \'echo \"\$0\"\' {} \\\;
name2
s=$(date +%s%N)
name2_num=$(name2 | wc -l)
e=$(date +%s%N)
name2_perf=$((e-s))
printf "  [# of files] $name2_num [Runtime(ns)] $name2_perf\n\n"

echo \> find \""$dir"\" -not -path \""$dir/prune_me*"\" -exec bash -c \'echo \"\$0\"\' {} \\\;
name3
s=$(date +%s%N)
name3_num=$(name3 | wc -l)
e=$(date +%s%N)
name3_perf=$((e-s))
printf "  [# of files] $name3_num [Runtime(ns)] $name3_perf\n\n"

echo "Cleaning up test files..."
cleanup
share|improve this answer
8  
Thank you for a very good analysis. Regarding "I strongly suspect this is the result of some caching" you can run this command: sudo sh -c "free && sync && echo 3 > /proc/sys/vm/drop_caches && free" to clear the cache (see unix.stackexchange.com/questions/87908/…). – ndemou Nov 19 '14 at 9:40
    
After few tests on those two with -prune I can tell there is rarely any difference. Do keep in mind that which command start first will benefit from cpu performance, the later cpu warm up > performance drop cause minor slow down (I did purge cache before each command as @ndemou suggestion) – Huy.PhamNhu Sep 28 '17 at 17:35
    
Try switch number among name1() name2() name3() in @BroSlow test script above to change execute order to get a visual about what I said. In real life, it is unnoticeable between those two though. – Huy.PhamNhu Sep 28 '17 at 17:47

One option would be to exclude all results that contain the directory name with grep. For example:

find . -name '*.js' | grep -v excludeddir
share|improve this answer
19  
This will make your search very slow – Dorian Feb 19 '13 at 12:01
1  
This one worked for me, others (which use -prune) - doesn't. – Andron Mar 28 '13 at 11:03
2  
Slow in large results, but useful in smaller sets. But how to exclude multiple directories using grep? Of course this way: find . -name '*.js' | grep -v excludeddir | grep -v excludedir2 | grep -v excludedir3 but there may be some one grep way. – Timo Kähkönen May 1 '13 at 9:47
    
Upvoted only for being easier to understand... – AhHatem Aug 19 '13 at 10:59
3  
If you want to perform multiple greps then you would be better off writing it as regular expressions: egrep -v '(dir1|dir2|dir3)'. However, in this specific case study, it would be better to exclude directories within find itself. – Laurence Nov 10 '14 at 9:58

I prefer the -not notation ... it's more readable:

find . -name '*.js' -and -not -path directory
share|improve this answer
4  
Sorry, it doesn't work. The man page for find says: "To ignore a directory and the files under it, use -prune". – Christian Davén Aug 25 '12 at 20:25
    
works for me... – sloven Mar 25 '13 at 14:58
5  
This is wrong. It doesn't prevent find from entering the directory and traversing all the files inside. – GetFree Apr 1 '13 at 1:37
1  
updated, -path is better choice in that case – mpapis Apr 1 '13 at 1:46
5  
@rane: More specifically find . -not -path "*/.git*" would be what you want. – Ben Nov 28 '13 at 17:50

Use the -prune option. So, something like:

find . -type d -name proc -prune -o -name '*.js'

The '-type d -name proc -prune' only look for directories named proc to exclude.
The '-o' is an 'OR' operator.

share|improve this answer
1  
This is the only pure-"find" solution that worked for me. The directories I wished to exclude are NOT immediately below the current working directory. – Lambart Apr 15 '13 at 23:06
2  
However, adding -print to the end may improve results. find . -type d -name .hg -prune -o -name data ignored the contents of the (multiple) .hg directories, but listed the .hg directories themselves. With -print, it only listed the "data" directories I was seeking. – Lambart Nov 4 '13 at 19:39

This is the format I used to exclude some paths:

$ find ./ -type f -name "pattern" ! -path "excluded path" ! -path "excluded path"

I used this to find all files not in ".*" paths:

$ find ./ -type f -name "*" ! -path "./.*" ! -path "./*/.*"
share|improve this answer

For a working solution (tested on Ubuntu 12.04 (Precise Pangolin))...

find ! -path "dir1" -iname "*.mp3"

will search for MP3 files in the current folder and subfolders except in dir1 subfolder.

Use:

find ! -path "dir1" ! -path "dir2" -iname "*.mp3"

...to exclude dir1 AND dir2

share|improve this answer

To exclude multiple directories:

find . -name '*.js' -not \( -path "./dir1" -o -path "./dir2/*" \)

To add directories, add -o -path "./dirname/*":

find . -name '*.js' -not \( -path "./dir1" -o -path "./dir2/*" -o -path "./dir3/*"\)

But maybe you should use a regular expression, if there are many directories to exclude.

share|improve this answer

You can use the prune option to achieve this. As in for example:

find ./ -path ./beta/* -prune -o -iname example.com -print

Or the inverse grep “grep -v” option:

find -iname example.com | grep -v beta

You can find detailed instructions and examples in Linux find command exclude directories from searching.

share|improve this answer
    
The grep solution is the only one that excludes all directories by the same name. When trying to exclude "node_modules" that is quite useful. – bmacnaughton May 8 '17 at 3:40

I was using find to provide a list of files for xgettext, and wanted to omit a specific directory and its contents. I tried many permutations of -path combined with -prune but was unable to fully exclude the directory which I wanted gone.

Although I was able to ignore the contents of the directory which I wanted ignored, find then returned the directory itself as one of the results, which caused xgettext to crash as a result (doesn't accept directories; only files).

My solution was to simply use grep -v to skip the directory that I didn't want in the results:

find /project/directory -iname '*.php' -or -iname '*.phtml' | grep -iv '/some/directory' | xargs xgettext

Whether or not there is an argument for find that will work 100%, I cannot say for certain. Using grep was a quick and easy solution after some headache.

share|improve this answer
find -name '*.js' -not -path './node_modules/*' -not -path './vendor/*'

seems to work the same as

find -name '*.js' -not \( -path './node_modules/*' -o -path './vendor/*' \)

and is easier to remember IMO.

share|improve this answer

The -path -prune approach also works with wildcards in the path. Here is a find statement that will find the directories for a git server serving multiple git repositiories leaving out the git internal directories:

find . -type d \
   -not \( -path */objects -prune \) \
   -not \( -path */branches -prune \) \
   -not \( -path */refs -prune \) \
   -not \( -path */logs -prune \) \
   -not \( -path */.git -prune \) \
   -not \( -path */info -prune \) \
   -not \( -path */hooks -prune \)  
share|improve this answer
 find . -name '*.js' -\! -name 'glob-for-excluded-dir' -prune
share|improve this answer
    
Can't get this one to work. find ~/Projects -name '*.js' -\! -name 'node_modules' -prune is still turning up files with node_modules in their path – mpen May 2 '17 at 16:17

None of previous answers is good on Ubuntu. Try this:

find . ! -path "*/test/*" -type f -name "*.js" ! -name "*-min-*" ! -name "*console*"

I have found this here

share|improve this answer
    
I don't see any reason why any of the answers with more than 100 points shouldn't work on Ubuntu. – Axel Beckert Sep 2 '15 at 0:10
    
Probably because I had errors? What do you think? – sixro Sep 2 '15 at 20:05

This is suitable for me on a Mac:

find . -name *.php -or -path "./vendor" -prune -or -path "./app/cache" -prune

It will exclude vendor and app/cache dir for search name which suffixed with php.

share|improve this answer

-prune definitely works and is the best answer because it prevents descending into the dir that you want to exclude. -not -path which still searches the excluded dir, it just doesn't print the result, which could be an issue if the excluded dir is mounted network volume or you don't permissions.

The tricky part is that find is very particular about the order of the arguments, so if you don't get them just right, your command may not work. The order of arguments is generally as such:

find {path} {options} {action}

{path}: Put all the path related arguments first, like . -path './dir1' -prune -o

{options}: I have the most success when putting -name, -iname, etc as the last option in this group. E.g. -type f -iname '*.js'

{action}: You'll want to add -print when using -prune

Here's a working example:

# setup test
mkdir dir1 dir2 dir3
touch dir1/file.txt; touch dir1/file.js
touch dir2/file.txt; touch dir2/file.js
touch dir3/file.txt; touch dir3/file.js

# search for *.js, exclude dir1
find . -path './dir1' -prune -o -type f -iname '*.js' -print

# search for *.js, exclude dir1 and dir2
find . \( -path './dir1' -o -path './dir2' \) -prune -o -type f -iname '*.js' -print
share|improve this answer

how-to-use-prune-option-of-find-in-sh is an excellent answer by Laurence Gonsalves on how -prune works.

And here is the generic solution:

find /path/to/search                    \
  -type d                               \
    \( -path /path/to/search/exclude_me \
       -o                               \
       -name exclude_me_too_anywhere    \
     \)                                 \
    -prune                              \
  -o                                    \
  -type f -name '*\.js' -print

To avoid typing /path/to/seach/ multiple times, wrap the find in a pushd .. popd pair.

pushd /path/to/search;                  \
find .                                  \
  -type d                               \
    \( -path ./exclude_me               \
       -o                               \
       -name exclude_me_too_anywhere    \
     \)                                 \
    -prune                              \
  -o                                    \
  -type f -name '*\.js' -print;         \
 popd
share|improve this answer

I found the functions name in C sources files exclude *.o and exclude *.swp and exclude (not regular file) and exclude dir output with this command:

find .  \( ! -path "./output/*" \) -a \( -type f \) -a \( ! -name '*.o' \) -a \( ! -name '*.swp' \) | xargs grep -n soc_attach
share|improve this answer

Better use the exec action than the for loop:

find . -path "./dirtoexclude" -prune \
    -o -exec java -jar config/yuicompressor-2.4.2.jar --type js '{}' -o '{}' \;

The exec ... '{}' ... '{}' \; will be executed once for every matching file, replacing the braces '{}' with the current file name.

Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation*.


Notes

* From the EXAMPLES section of the find (GNU findutils) 4.4.2 man page

share|improve this answer
1  
Very old question, but still with room for improvements. I found it by chance trying to solve a similar problem, and none of the answers were satisfactory. – Alberto Aug 28 '15 at 8:27
    
I use the exec action often and find it very useful. I typically add quotes between the {} in case there are spaces in the file paths which gives "{}". – lkuty Dec 31 '15 at 8:06
    
@lkuty I was about to edit my post to reflect your comment, but after a quick test (without quoting, {} does work for files with whitespaces in their names) and a look into the man pages, it seems that quoting is only necessary to avoid them to be misinterpreted as shell script punctuation. In this case, you would use single quoting: '{}' – Alberto Jan 15 '16 at 13:52
    
I think that I had to use it to make cp or mv or rm. I will check it out – lkuty Jan 15 '16 at 17:22

This works because find TESTS the files for the pattern "*foo*":

find ! -path "dir1" ! -path "dir2" -name "*foo*"

but it does NOT work if you don't use a pattern (find does not TEST the file). So find makes no use of its former evaluated "true" & "false" bools. Example for not working use case with above notation:

find ! -path "dir1" ! -path "dir2" -type f

There is no find TESTING! So if you need to find files without any pattern matching use the -prune. Also, by the use of prune find is always faster while it really skips that directories instead of matching it or better not matching it. So in that case use something like:

find dir -not \( -path "dir1" -prune \) -not \( -path "dir2" -prune \) -type f

or:

find dir -not \( -path "dir1" -o -path "dir2" -prune \) -type f

Regards

share|improve this answer

For FreeBSD users:

 find . -name '*.js' -not -path '*exclude/this/dir*'
share|improve this answer
2  
This is the same as GetFree's answer. – Kenster Aug 31 '15 at 11:46
    
I know it is but since I spent more minutes than I like on such easy task I decided to add answer specifically for FreeBSD users – Richard Bartisek Sep 1 '15 at 13:29

If search directories has pattern (in my case most of the times); you can simply do it like below:

find ./n* -name "*.tcl" 

In above example; it searches in all the sub-directories starting with "n".

share|improve this answer

I have found the suggestions on this page and a lot of other pages just do not work on my Mac OS X system. However, I have found a variation which does work for me.

The big idea is to search the Macintosh HD but avoid traversing all the external volumes, which are mostly Time Machine backups, image backups, mounted shares, and archives, but without having to unmount them all, which is often impractical.

Here is my working script, which I have named "findit".

#!/usr/bin/env bash
# inspired by http://stackoverflow.com/questions/4210042/exclude-directory-from-find-command Danile C. Sobral
# using special syntax to avoid traversing. 
# However, logic is refactored because the Sobral version still traverses 
# everything on my system

echo ============================
echo find - from cwd, omitting external volumes
date
echo Enter sudo password if requested
sudo find . -not \( \
-path ./Volumes/Archive -prune -o \
-path ./Volumes/Boot\ OS\ X -prune -o \
-path ./Volumes/C \
-path ./Volumes/Data -prune -o \
-path ./Volumes/jas -prune -o \
-path ./Volumes/Recovery\ HD -prune -o \
-path ./Volumes/Time\ Machine\ Backups -prune -o \
-path ./Volumes/SuperDuper\ Image -prune -o \
-path ./Volumes/userland -prune \
\) -name "$1" -print
date
echo ============================
iMac2:~ jas$

The various paths have to do with external archive volumes, Time Machine, Virtual Machines, other mounted servers, and so on. Some of the volume names have spaces in them.

A good test run is "findit index.php", because that file occurs in many places on my system. With this script, it takes about 10 minutes to search the main hard drive. Without those exclusions, it takes many hours.

share|improve this answer

i wanted to know the number of directories, files an MB of just the current directory - and that code does exactly what i want :-)

the source

- ...    2791037 Jun  2  2011 foo.jpg
- ... 1284734651 Mär 10 16:16 foo.tar.gz
- ...          0 Mär 10 15:28 foo.txt
d ...       4096 Mär  3 17:12 HE
d ...       4096 Mär  3 17:21 KU
d ...       4096 Mär  3 17:17 LE
d ...          0 Mär  3 17:14 NO
d ...          0 Mär  3 17:15 SE
d ...          0 Mär  3 17:13 SP
d ...          0 Mär  3 17:14 TE
d ...          0 Mär  3 19:20 UN

the code

format="%s%'12d\n"

find . -type d -not -path "./*/*" | wc -l | awk -v fmt=$format '{printf fmt, " Anzahl Ordner  = ", $1-1}'
find . -type f -not -path "./*/*" | wc -l | awk -v fmt=$format '{printf fmt, " Anzahl Dateien = ", $1}'
  du . -hmS --max-depth=0 | awk -v fmt=$format '{printf fmt, " Groesse (MB)   = ", $1}'

note: the extra format="%s%'12d\n" is necessary for awk to format the numbers.

the result

Anzahl Ordner  =            8
Anzahl Dateien =            3
Groesse (MB)   =        1.228
share|improve this answer

Not sure if this would cover all edge cases, but following would be pretty straight forward and simple to try:

ls -1|grep -v -e ddl -e docs| xargs rm -rf

This should remove all files/directories from the current directory excpet 'ddls' and 'docs'.

share|improve this answer

I tried command above, but none of those using "-prune" works for me. Eventually I tried this out with command below:

find . \( -name "*" \) -prune -a ! -name "directory"
share|improve this answer

For those of you on older versions of UNIX who cannot use -path or -not

Tested on SunOS 5.10 bash 3.2 and SunOS 5.11 bash 4.4

find . -type f -name "*" -o -type d -name "*excluded_directory*" -prune -type f
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.