linux cat 文件,不包括以特定前缀开头的文件

linux cat files excluding the ones beginning with a certain prefix

我正在尝试将目录中的所有 png 文件分类并通过管道将它们传送到 ffmpeg 命令:

cat *.png | ffmpeg

它有效,但我现在想从列表中排除所有以前缀 'legend_' 开头的 png 文件。我如何实现这一目标?我知道使用 ls 我可以输入:

ls -I legend_* -I *.jpg

我找到了有关 grep、ls 等的信息,但有关于命令 cat 的令人困惑的信息,none 似乎像使用

一样工作
!(legend_)
! -name legend_

您可以使用 find:

find . -name '*.png' ! -name 'legend_*' -exec cat {} \; | ffmpeg

与bash,使用extglob选项,可以这样写:

shopt -s extglob
ls !(legend_*).png

由于 extglob 选项不符合 POSIX,这意味着它不能保证在 POSIX shell 中工作,我建议使用 find.