Tim
Tim

Reputation: 99526

"find" files under current directory but skipping some specific sub-directories

I wonder how to specify to the command find for searching files under current directory but skipping some specific sub-directories.

For example, I would like to skip sub-directories that match ./dir1/*.1/.

If I would like to exclude subdirectories that match ./dir1/train*.1/, ./dir2/train*.3/, ./dir1/dir3/train*.2/..., how can I specify all of them? I tried -path '\*/train*.*' -prune but it does not work.

Upvotes: 2

Views: 4320

Answers (2)

Donal Fellows
Donal Fellows

Reputation: 137757

You need to use the -path option and the -prune option, like this:

find . -type d -path "./dir1/*.1" -prune -o -print

Upvotes: 7

nc3b
nc3b

Reputation: 16250

Check this out. EDIT: Straight from the man page: `To ignore a directory and the files under it, use -prune'.

Upvotes: 2

Related Questions