2017-08-16 57 views
0
rm -i test_file* 
rm: remove regular empty file 'test_file'? 
rm: remove regular file 'test_file1'? 

我想回答“是”,在关键词存在的提示,并没有回答其他。如何应对Linux提示符(基于关键词的提示)

我试过(它不工作)

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

您正在使用哪个Shell'bash'?从命令输出中搜索不是有效的方法,你可以使用'find'吗?如果你的目的是删除所有的零字节文件? – Inian

+0

@Inian是对的,'找到。 -name“test_file *”-type f -empty -delete'窍门 – peyo

回答

1

当您打字:

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

你传入yes结果grep具有不知道它应该通过yes结果rm

您可以在单个文件上以这种方式(在bash上)执行此操作:

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

在多个文件(仍然庆典):

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

它涉及两个删除单个文件的调用! – Ravichandra

+0

那么,OP中的'find'-based解决方案仍在工作;) – peyo

+0

Yah,但我在寻找回复提示逻辑:) – Ravichandra