Delete items extracted from file

I have several .mkv files in eng.md that are listed by codes

  $ 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 

I decided to delete mkv files using pipeline methods and try

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

Try alternatively

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

How to solve such a problem?

+3
source share
3 answers

Like this (if only this huge list of files exceeds the maximum command line length ):

 rm $(grep -i mkv eng.md) 
+4
source

Since none of the comments really gave a solution that works for each situation, I propose here an approach slightly modified from what the shirsh suggested in his comment:

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

I recommend find

find . -type f -iname '*.mkv' -exec rm '{}' \;

-1
source

Source: https://habr.com/ru/post/1276077/


All Articles