1

假设我在 a 目录中有所有这些文件:

$ ls
file1 file2 file3 file4 ... file200

我想删除所有文件,但file4. 在zsh我习惯这样做:

$ rm ^file4

我该怎么做fish呢?

4

2 回答 2

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

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

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

请注意http://fishshell.com/docs/current/commands.html#continue上的代码示例

于 2014-02-13T16:06:17.467 回答
2

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

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

编辑

更简单的用例的较短的:

ls | grep -v file4 | xargs rm
于 2014-02-14T09:32:49.607 回答