rm < junkfilelist.txt

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
ry2ngh [ Di, 20 November 2007 19:56 ] [ ID #1874660 ]

Re: rm < junkfilelist.txt

In article <4a185455-13da-4d00-b97b-795bf43ab6c6 [at] n20g2000hsh.googlegroups.com>,
<ry2ngh [at] 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
>

man xargs
gazelle [ Di, 20 November 2007 20:16 ] [ ID #1874662 ]

Re: rm < junkfilelist.txt

On 2007-11-20, ry2ngh [at] 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 <http://cfaj.freeshell.org/shell/>
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
cfajohnson [ Di, 20 November 2007 21:24 ] [ ID #1874666 ]

Re: rm < junkfilelist.txt

Thanks Chris and Kenny, that solved my problem.

-Ryan
ry2ngh [ Di, 20 November 2007 21:48 ] [ ID #1874667 ]

Re: rm < junkfilelist.txt

On Nov 20, 10:56 am, ry2... [at] 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`
x77770 [ Do, 22 November 2007 07:21 ] [ ID #1876344 ]
Linux » comp.unix.shell » rm < junkfilelist.txt

Vorheriges Thema: sql statement in a here document - 2nd try
Nächstes Thema: More awk questions