LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 12-11-2010, 09:51 AM   #1
e3399
Member
 
Registered: Nov 2010
Location: China
Distribution: Fedora12
Posts: 54

Rep: Reputation: 0
rm: invalid option -- 'w'. Why this happened?


[test@localhost scripts]$ ll | grep -v 'sh'
total 12
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 +
-rw-rw-r--. 1 test test 0 2010-12-11 23:35 f
-rw-rw-r--. 1 test test 0 2010-12-11 23:35 fdate
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 filename
-rw-rw-r--. 1 test test 0 2010-12-11 23:40 filename20101209
-rw-rw-r--. 1 test test 0 2010-12-11 23:40 filename20101210
-rw-rw-r--. 1 test test 0 2010-12-11 23:40 filename20101211
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 filenamedate
-rw-rw-r--. 1 test test 0 2010-12-11 23:25 ll
-rw-rw-r--. 1 test test 0 2010-12-11 23:25 lldate
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 test
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 testdate
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 %Y%m%d
-rw-rw-r--. 1 test test 0 2010-12-11 23:37 +%Y%m%d

[test@localhost scripts]$ ll | grep -v 'sh' | xargs rm
rm: invalid option -- 'w'
Any help will be appreciated.
 
Old 12-11-2010, 10:03 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
'find . -type f -not -iname sh -print0|xargs -0 rm'[EDIT]: 'll' may be an alias meaning "long listing" so all the args are seen by 'rm' as either entities or switches. Perfect example why people shouldn't use 'ls' in the first place.[/EDIT]

Last edited by unSpawn; 12-11-2010 at 10:05 AM.
 
Old 12-11-2010, 10:19 AM   #3
e3399
Member
 
Registered: Nov 2010
Location: China
Distribution: Fedora12
Posts: 54

Original Poster
Rep: Reputation: 0
Thank you.
 
Old 12-11-2010, 10:53 AM   #4
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
This probably will do better than what the OP is thinking:

Code:
ls | grep -v ".sh" | xargs rm -rf
You see, ls unlike ll doesn't list modes or anything like that by default, so technically because of that rm doesn't think those modes (i.e. -rw-rw-r--) are switches, flags, or options passed to rm.
 
1 members found this post helpful.
Old 12-11-2010, 11:30 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Using 'ls' is like using 'cat file|grep' (grep file) or 'ps|grep -v grep|grep processname' (pgrep processname) so IMHO using 'find' still is the lesser error-prone way: for instance 'find' can use "-print0" and xargs understands that with "-0" while 'ls' can't even print output and null terminate it.
 
Old 12-11-2010, 11:39 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by e3399 View Post
[test@localhost scripts]$ ll | grep -v 'sh'
total 12
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 +
-rw-rw-r--. 1 test test 0 2010-12-11 23:35 f
-rw-rw-r--. 1 test test 0 2010-12-11 23:35 fdate
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 filename
-rw-rw-r--. 1 test test 0 2010-12-11 23:40 filename20101209
-rw-rw-r--. 1 test test 0 2010-12-11 23:40 filename20101210
-rw-rw-r--. 1 test test 0 2010-12-11 23:40 filename20101211
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 filenamedate
-rw-rw-r--. 1 test test 0 2010-12-11 23:25 ll
-rw-rw-r--. 1 test test 0 2010-12-11 23:25 lldate
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 test
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 testdate
-rw-rw-r--. 1 test test 0 2010-12-11 23:13 %Y%m%d
-rw-rw-r--. 1 test test 0 2010-12-11 23:37 +%Y%m%d

[test@localhost scripts]$ ll | grep -v 'sh' | xargs rm
rm: invalid option -- 'w'
Any help will be appreciated.
What would you expect to happen if you entered the command:

Code:
rm total 1 -rw-rw-r--. 1 test test   0 2010-12-11 23:13 +
 
  


Reply



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
ls *txt* returns invalid option --e Eh ??? MrMark Linux - Newbie 8 12-21-2016 10:20 AM
dkmraid -i invalid option sang_froid Linux - General 0 10-16-2006 08:50 AM
cp indicates invalid option Murdock1979 Linux - Software 1 01-24-2006 02:21 AM
Whatever happened to the kill menu option... audibel Linux - General 2 04-14-2005 07:47 PM
in.telnetd: invalid option -- L implant23 Linux - Networking 1 12-01-2002 11:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:10 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
Open Source Consulting | Domain Registration