Scripting question how to filter list of files based on globs

Paul D newtwen at gmail.com
Tue Apr 9 17:03:09 PDT 2024


On 2024-04-09 23:30, Philip Prindeville via openwrt-devel wrote:
> I'm trying to modify a script generates a list of filenames one per 
> line, but should be filtered against a blacklist of file globs.
> 
> Something like:
> 
> % find dir <args> -print | grep -v -f blacklist


I got this. When I run it on the openwrt source, where package is the packages directory:

Vanilla Output

find package -type f -print

===
...
package/utils/uencrypt/src/CMakeLists.txt
package/utils/uencrypt/src/uencrypt-mbedtls.c
package/utils/uencrypt/src/uencrypt-openssl.c
package/utils/uencrypt/src/uencrypt.c
package/utils/uencrypt/src/uencrypt.h
package/utils/uencrypt/Makefile
package/utils/zyxel-bootconfig/Makefile
package/utils/zyxel-bootconfig/files/95_apply_bootconfig
package/utils/zyxel-bootconfig/src/Makefile
package/utils/zyxel-bootconfig/src/zyxel-bootconfig.c
package/utils/ucode-mod-bpf/Makefile
package/utils/ucode-mod-bpf/src/bpf.c
package/utils/firmware-utils/Makefile
package/utils/yafut/Makefile
package/utils/debugcc/Makefile
===


Exclude 'Makefile's

find package -type f -name 'Makefile' -prune -o -type f -print

===
...
package/utils/util-linux/patches/001-meson-properly-handle-gettext-non-existence.patch
package/utils/uencrypt/src/CMakeLists.txt
package/utils/uencrypt/src/uencrypt-mbedtls.c
package/utils/uencrypt/src/uencrypt-openssl.c
package/utils/uencrypt/src/uencrypt.c
package/utils/uencrypt/src/uencrypt.h
package/utils/zyxel-bootconfig/files/95_apply_bootconfig
package/utils/zyxel-bootconfig/src/zyxel-bootconfig.c
package/utils/ucode-mod-bpf/src/bpf.c
===

Exclude Makefiles and c files

find package -type f -name 'Makefile' -o -name '*.c' -prune -o -type f -print

===
...
package/utils/util-linux/patches/001-meson-properly-handle-gettext-non-existence.patch
package/utils/uencrypt/src/CMakeLists.txt
package/utils/uencrypt/src/uencrypt.h
package/utils/zyxel-bootconfig/files/95_apply_bootconfig
===

Exclude Makefiles and c files and patch files


find package -type f -name 'Makefile' -o -name '*.c' -o -name '*.patch' -prune -o -type f -print
===
...
package/utils/uencrypt/src/CMakeLists.txt
package/utils/uencrypt/src/uencrypt.h
package/utils/zyxel-bootconfig/files/95_apply_bootconfig
===

find package -type f -name 'Makefile' -o -type d -name 'utils' -prune -o -type f -print

===
...
===


Set your -type accordingly.



More information about the openwrt-devel mailing list