TransWikia.com

About using find with prune option

Unix & Linux Asked by Dominique Crétel on January 2, 2022

I have a source folder where you can find files with extensions .c, .pc, .pro.c.

I want to find all files with .c and .pc only, since .pro.c is a generated file from .pc after preprocessing.

Here is my find expression which is not yet correct:

find source ( ( -name '*.pro.c' ) -a -prune ) -o ( -name '*.c' -a -print )

What is my mistake ?

Can someone help me and explain why I do not get the correct result ?

Thank you.

One Answer

-prune applies to directories, not files, and instructs find not to descend into the directory it’s looking at.

You only need to negate a name test:

find source -name '*.c' ! -name '*.pro.c' -o -name '*.pc'

Answered by Stephen Kitt on January 2, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP