Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

find

bash

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.

like image 334
Tim Avatar asked Nov 24 '25 13:11

Tim


2 Answers

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

find . -type d -path "./dir1/*.1" -prune -o -print
like image 118
Donal Fellows Avatar answered Nov 26 '25 17:11

Donal Fellows


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

like image 32
nc3b Avatar answered Nov 26 '25 18:11

nc3b