删除从文件中捕获的元素

时间:2018-03-26 03:50:22

标签: bash shell

我在.mkv中有多个eng.md个文件,按代码列出

    $ grep -i 'mkv' eng.md
    ./Volumes/Transcend/Downloads/The.Adventure.of.English.Ep4.mkv
    ./Volumes/Transcend/Downloads/The.Adventure.of.English.Ep5.mkv
    ./Volumes/Transcend/Downloads/The.Adventure.of.English.Ep6.mkv
    ./Volumes/Transcend/Downloads/The.Adventure.of.English.Ep7.mkv
    ./Volumes/Transcend/Downloads/._The.Adventure.of.English.Ep4.mkv
    ./Volumes/Transcend/Downloads/The.Adventure.of.English.Ep8.mkv
    ./Volumes/Transcend/Downloads/._The.Adventure.of.English.Ep8.mkv
    ./Volumes/Transcend/Downloads/._The.Adventure.of.English.Ep5.mkv
    ./Volumes/Transcend/Downloads/._The.Adventure.of.English.Ep6.mkv

我决定使用管道方法删除mkv文件并尝试

$ rm < grep -i 'mkv' eng.md
-bash: grep: No such file or directory

尝试另选

$ grep -i 'mkv' eng.md | rm 
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
grep: eng.md: No such file or directory

如何解决这个问题?

2 个答案:

答案 0 :(得分:4)

像这样,(除非它是exceeds the command line maximum length)的一些巨大文件列表:

rm $(grep -i mkv eng.md)

答案 1 :(得分:3)

由于这两条评论都没有真正提供适合各种情况的解决方案,我在这里提出的方法略微修改了他的评论中提出的措辞:

grep '[.]mkv$' eng.md | xargs rm