LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-03-2009, 09:27 AM   #1
mard25
LQ Newbie
 
Registered: Jun 2009
Location: india, south
Distribution: suse, ubuntu
Posts: 7

Rep: Reputation: 0
Unhappy bash command - rm - lost my Redirections?


Why don't any of the following work?
I am trying to delete files using a text filelist.

$cat filelist.txt |rm -rf

$cat filelist.txt |exec rm -rf #(desperation!)

$rm -rf <cat filelist.txt

$rm -rf <filelist.txt

$rm -rf 'cat filelist.txt'

I am using GNU rm version 6.11 from Suse 11.1.
 
Old 06-03-2009, 09:58 AM   #2
permalac
Member
 
Registered: Jul 2007
Location: Barcelona
Posts: 115

Rep: Reputation: 16
if you use lsattr on the files that don't get erased, does them appear as

Code:
------------------- ./Videos
Or they have an "I" somewhere?



Otherwise you can try to echo rm -rf ...... and you'll know what are you trying to erase.
 
Old 06-03-2009, 10:44 AM   #3
mard25
LQ Newbie
 
Registered: Jun 2009
Location: india, south
Distribution: suse, ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by permalac View Post
if you use lsattr on the files that don't get erased, does them appear as

Code:
------------------- ./Videos
Or they have an "I" somewhere?



Otherwise you can try to echo rm -rf ...... and you'll know what are you trying to erase.
Ran $lsattr on the files and the output was as in your code.

$echo rm -rf

-seems to repeat the command itself

rm -rf

Thanks for the suggestions.
 
Old 06-03-2009, 10:58 AM   #4
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 25
Hello.

`rm` wants its list of files to delete as command line arguments. By using pipes you are sending said file names as input [stdin]. What you need is something along the lines of:

Code:
$ cat FILELIST | xargs rm
Further research pipes and the `xargs` utility to fully understand why.
 
Old 06-03-2009, 11:06 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by mard25 View Post
Why don't any of the following work?
I am trying to delete files using a text filelist.

$cat filelist.txt |rm -rf

$cat filelist.txt |exec rm -rf #(desperation!)

$rm -rf <cat filelist.txt

$rm -rf <filelist.txt

$rm -rf 'cat filelist.txt'

I am using GNU rm version 6.11 from Suse 11.1.

Code:
awk 'BEGIN{q="\042"}
{
 cmd="rm -rf "q $0 q
 cmd |getline
 close(cmd)
} filelist
 
Old 06-03-2009, 11:22 AM   #6
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by mard25 View Post
Why don't any of the following work?
I am trying to delete files using a text filelist.

$cat filelist.txt |rm -rf

$cat filelist.txt |exec rm -rf #(desperation!)

$rm -rf <cat filelist.txt

$rm -rf <filelist.txt

$rm -rf 'cat filelist.txt'

I am using GNU rm version 6.11 from Suse 11.1.
Bro this is what u want :

Quote:
cat filename.txt | while read file; do rm -f "$file"; done
 
Old 06-03-2009, 11:25 AM   #7
mard25
LQ Newbie
 
Registered: Jun 2009
Location: india, south
Distribution: suse, ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
hello noctilucent

$cat FILELIST |xargs rm

-worked on all files with no spaces in the name.

Am trying out ghostdog74's awk script now
 
Old 06-03-2009, 11:44 AM   #8
mard25
LQ Newbie
 
Registered: Jun 2009
Location: india, south
Distribution: suse, ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
hello ghostdog74

worked like a charm. Will someday figure out why.

Thanks
 
Old 06-03-2009, 11:48 AM   #9
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by divyashree View Post
Bro this is what u want :
Code:
cat filename.txt | while read file; do rm -f "$file"; done
useless cat.
Code:
while read file; do rm -f "$file"; done < file
 
Old 06-03-2009, 12:01 PM   #10
mard25
LQ Newbie
 
Registered: Jun 2009
Location: india, south
Distribution: suse, ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
hello divyshree

yours worked too

Thanks

PS - The 'Thank you' button seems to have vanished on all posts on my page.
 
Old 06-03-2009, 12:05 PM   #11
mard25
LQ Newbie
 
Registered: Jun 2009
Location: india, south
Distribution: suse, ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
Smile

xarrrrrgs!!

reading up that command now.

Thanks all
 
Old 06-03-2009, 09:53 PM   #12
mard25
LQ Newbie
 
Registered: Jun 2009
Location: india, south
Distribution: suse, ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
As a footnote, would this zap all duplicate files in a directory?

$fdupes -rf DIR |xargs -0 -rf
 
Old 06-03-2009, 10:04 PM   #13
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by mard25 View Post
As a footnote, would this zap all duplicate files in a directory?

$fdupes -rf DIR |xargs -0 -rf
why don't you create a dummy directory and try it out ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
redirections in C xeon123 Programming 2 10-21-2007 01:47 PM
Handling I/O redirections in my shell. Sebouh Programming 2 04-10-2007 02:31 PM
Apache redirections spanishwasabi Linux - Server 2 08-18-2006 12:04 PM
dns server and redirections prasadlinuxguy Linux - Networking 1 06-08-2006 12:51 AM
redirections between directories/files basher400 Linux - Newbie 9 06-21-2005 09:44 AM


All times are GMT -5. The time now is 09:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration