Read & Remove files containing space in its name

read past tense
read meaning
read theory
read online
read synonym
(read ) usage
i read a book
reading plus

I have to read the list of file names from file A.txt,Where the file names has space in it,So can't able remove.File A.txt is given below

20150726140135_Content 1.mp4
20150726162955_Content 1.mp4
20150726163056_Content 3.mp4
20150726164057_Content 5.mp4
20150726170315_Tab main 2.mp4

for f in $(cat A.txt) ; do 
   rm "/tmp/$f";
done

While try this the file breaking into two which causes the error

rm: cannot remove `/tmp/20150726170315_Tab': No such file or directory
rm: cannot remove `/tmp/2': No such file or directory

for i in $(cat)

is a common antipattern in bash. You should not use a for loop to read lines. This doesn't work because:

  1. First $(cat A.txt) is expanded to 20150726140135_Content 1.mp4 20150726162955_Content 1.mp4 20150726163056_Content 3.mp4 20150726164057_Content 5.mp4 20150726170315_Tab main 2.mp4 (no quotes).

  2. Then shell executes the command for i in 20150726140135_Content 1.mp4 20150726162955_Content 1.mp4 20150726163056_Content 3.mp4 20150726164057_Content 5.mp4 20150726170315_Tab main 2.mp4. Newlines and spaces are intepreted as arguments separators.

To read a file line by line in bash use a while IFS= read -r loop:

while IFS= read -r f; do 
   rm "/tmp/$f";
done < A.txt

Verb 'To Read' - Irregular Verb Definition, discover (information) by reading it in a written or printed source. to read or peruse written or printed matter. to utter aloud or render in speech written or printed words that one is perusing: to read to a person.


You can use xargs. The -I' will use line based input.

xargs -i{} rm /tmp/{} < file.txt

Read, inspect and record the figure indicated on (a measuring instrument). To discern and interpret the nature or significance of through close examination or sensitive observation: The tracker read the trail for signs of game.


if you want to remove files starting with 2015 or any other pattern

while IFS='\s' read -r f; do 
   rm $f*;
done

Read, hear and understand the words of (someone speaking on a radio transmitter). 11 synonyms of read from the Merriam-Webster Thesaurus, plus 43 related words, definitions, and antonyms. Find another word for read. Read: to go over and mentally take in the content of.


Read, to utter aloud or render in speech (something written, printed, etc.): reading a story to his children; The actor read his lines in a booming voice. to have such  Synonyms for read at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for read.


read, read definition: 1. to look at words or symbols and understand what they mean: 2. to say the words that are printed…. Learn more. Kindle Cloud Reader lets you read ebooks instantly in your web browser - no Kindle device required.


READ, read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf. On files that support seeking, the read operation commences at the  Learning to read can be easy and fun! Reading Eggs makes learning to read interesting and engaging for kids, with great online reading games and activities.. And it really works! Children love the games, songs, golden eggs and other rewards which, along with feeling proud of their reading, really motivate children to keep exploring and learning.