如何 return 每个想要的文件,不包括 zsh 中的特定后缀

how to return every wanted file excluding specific suffix in zsh

我想将目标文件作为命令的输入。

我的目录目前混合了目标文件权重文件。 (简化)

(base) directory % ls 
file_015_apple.txt
file_015_orange.txt
file_016_apple.txt
file_016_orange.txt
file_017_apple.txt
file_017_apple.weight.txt
file_017_orange.txt
file_017_orange.weight.txt
...

我只想 return 目标文件,但不使用 grep。
因为命令不可读。

ls -l file* | grep -v "weight"

我尝试了很多东西都失败了。

 1044  ls file*.txt ! -name "*weight*"
 1045  ls file*.txt ! -name *weight*
 1046  ls file*.txt ^*weight*
 1049  ls file*(^weight).txt
 1055  ls file*.txt/^*weight.txt

如果我放入所有文件,则会发生错误。

% command file_*.txt

*Error*: field_017_apple.weight.weight.txt not found

有什么解决办法吗?

尝试以下操作:

ls *~*weight.txt

您可能需要启用扩展的 glob 选项:

setopt extendedglob