rm < junkfilelist.txt

rm < junkfilelist.txt

am 20.11.2007 19:56:28 von ry2ngh

I have a list of files that I want to delete from a directory. Is
there a way to pipe this list to a comand line such as

$ rm < junkfilelist.txt

(this produces an error message and does not remove the files)

Or is the solution more complicated than this?

Thanks,

-Ryan

Re: rm < junkfilelist.txt

am 20.11.2007 20:16:01 von gazelle

In article <4a185455-13da-4d00-b97b-795bf43ab6c6@n20g2000hsh.googlegroups.com>,
wrote:
>I have a list of files that I want to delete from a directory. Is
>there a way to pipe this list to a comand line such as
>
>$ rm < junkfilelist.txt
>
>(this produces an error message and does not remove the files)
>
>Or is the solution more complicated than this?
>
>Thanks,
>
>-Ryan
>

man xargs

Re: rm < junkfilelist.txt

am 20.11.2007 21:24:44 von cfajohnson

On 2007-11-20, ry2ngh@gmail.com wrote:
>
>
> I have a list of files that I want to delete from a directory. Is
> there a way to pipe this list to a comand line such as
>
> $ rm < junkfilelist.txt
>
> (this produces an error message and does not remove the files)
>
> Or is the solution more complicated than this?

rm does not read filenames from the standard input; it requires
them to be on the command line. If the file is small, you can use:

rm $( cat junkfilelist.txt )

Otherwise, use xargs:

xargs rm < junkfilelist.txt

Both methods will fail if the filenames contain spaces or other
pathological characters. In that case, you can use a loop:

while IFS= read -r file
do
rm -- "$file"
done < junkfilelist.txt

Or:

awk '{ printf "rm -v -- \"%s\"\n", $0 }' junkfilelist.txt | sh

The latter will have problems if names contain quotes. If they do,
add a gsub() statement to escape them.

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Re: rm < junkfilelist.txt

am 20.11.2007 21:48:50 von ry2ngh

Thanks Chris and Kenny, that solved my problem.

-Ryan

Re: rm < junkfilelist.txt

am 22.11.2007 07:21:40 von x77770

On Nov 20, 10:56 am, ry2...@gmail.com wrote:
> I have a list of files that I want to delete from a directory. Is
> there a way to pipe this list to a comand line such as
>
> $ rm < junkfilelist.txt
>
> (this produces an error message and does not remove the files)
>
> Or is the solution more complicated than this?
>
> Thanks,
>
> -Ryan

rm `cat junkfilelist.txt`