否定鱼壳中的参数扩展

时间:2014-02-13 13:28:32

标签: fish glob

让我们说在我的目录中包含所有这些文件:

$ ls
file1 file2 file3 file4 ... file200

我想删除file4以外的所有文件。在zsh我习惯这样做:

$ rm ^file4

我如何使用fish

执行此操作

2 个答案:

答案 0 :(得分:3)

这是一种方式。

set files *
set i 1; for f in $files; test $f = file4; and break; or set i (math $i+1); end
set -e files[$i]
echo rm $files

由于鱼的目标是精益,因此数组或文件名操作的方式并不多。你也可以坚持一个简单的循环:

for f in *; test $f != file4; and echo rm $f; end

请注意http://fishshell.com/docs/current/commands.html#continue

上的代码示例

答案 1 :(得分:2)

您可以使用find命令,该命令通常更强大。虽然写一点不方便。

find . -not -name file4 -type f | xargs rm

修改

较简单的用例:

ls | grep -v file4 | xargs rm