feed a list of files to 'rm'?

Hard and soft ware discusion.

Moderator: Moderators

Postby DenisF » Fri Aug 27, 2004 12:58 pm

Iv'e been beating my head against the wall on this for ages..

Lets say i do something like locate evilfile > badfiles.list,
after locate is done, a file with a list like this;
"
/home/b/baduser/badfile
[ 4998 more entries here ]
/home/a/anotherbaduser/badfile
"

is created under the name of 'badfiles.list'

Now, how do i make 'rm' delete all of the files in that list, and not the list itself?
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby sjaz » Fri Aug 27, 2004 7:47 pm

urm ...

locate evilfile > badfiles.list
cat badfiles.list | rm

?
User avatar
sjaz
Forum Admin
Forum Admin
 
Posts: 689
Joined: Fri Feb 14, 2003 11:08 pm
Location: London, UK

Postby DenisF » Wed Sep 01, 2004 8:25 am

Oddly enough, feeding list(s) of file(s) to rm doesn't seem to do the trick for me

root@mandrake/home/d/denisf# cat badfiles.list | rm
rm: too few arguments
Try `rm --help' for more information.

if i add an -f to rm, it does nothing..

ideas?
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby naveed » Thu Sep 02, 2004 4:25 pm

i have got the same problem few days back and after writing 2 lines of bash code i thought i am going right but my code failed in the case when list contains any space between file name or etc..
however i found this code (somewhat long but well)
Code: Select all
#!/bin/bash
file1=badfiles.list
tmp1=tmp1
tmp2=tmp2

while IFS= read -r line
do
eval "set -- $line"
if [ -z "$4" ]; then break; fi
rm "$4"
grep -v ""$4"" $tmp1 > $tmp2
mv "$tmp2" "$tmp1"
done < "$file1"

naveed
Newbie
 
Posts: 8
Joined: Sat Jul 31, 2004 4:17 pm

Postby DenisF » Sun Dec 05, 2004 6:27 am

Actually, iv'e just discovered america [after all these years...]

rm `locate badfile`
works like a charm!
same way if u already have a list of files to remove;
rm `cat badfiles.list`

damn i love me
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell


Return to Computers

Who is online

Users browsing this forum: No registered users and 2 guests

cron