gpt4 book ai didi

linux - 如何回复linux提示(根据提示中的关键字)

转载 作者:太空宇宙 更新时间:2023-11-04 10:16:56 25 4
gpt4 key购买 nike

rm -i test_file*
rm: remove regular empty file 'test_file'?
rm: remove regular file 'test_file1'?

我想在提示中出现的关键字empty中回答“yes”,在not中回答其他。

我试过了(没用)

yes | grep "empty" | rm -i test_file*

最佳答案

当你打字时:

yes | grep "empty" | rm -i test_file*

您正在将 yes 结果传递给 grep,它不知道它应该将 yes 结果传递给 rm

您可以(在 bash 上)对单个文件执行此操作:

file test_file |grep empty && yes | rm -i test_file

在多个文件上(仍然是 bash):

for file in *.dat; do file $file | grep empty && yes | rm -v $file ; done

关于linux - 如何回复linux提示(根据提示中的关键字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45710595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com