假设我在 a 目录中有所有这些文件:
$ ls
file1 file2 file3 file4 ... file200
我想删除所有文件,但file4
. 在zsh
我习惯这样做:
$ rm ^file4
我该怎么做fish
呢?
这是一种方法。
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上的代码示例
您可以使用该find
命令,该命令通常更强大。虽然写起来有点不方便。
find . -not -name file4 -type f | xargs rm
编辑
更简单的用例的较短的:
ls | grep -v file4 | xargs rm