LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-15-2007, 10:44 AM   #1
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
removing file with special characters


Accidentally a file was created with the name "--some-option", e.g. name starts with two dashes. I can't remove this file from the shell. I tried single and double quotes, escaping leading dashes, but to no avail. All I am getting:
rm: unrecognized option `--some-option'
or
rm: cannot remove `\\--some-option' No such file or directory

Konqueror removes file without a problem. I tried to search for the answer, but could not find it.
 
Old 02-15-2007, 10:48 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
It's removed easily:
Code:
rm -- --some-option
The two lines (--) tell rm that no more options are given, the next argument is filename.
 
Old 02-15-2007, 11:00 AM   #3
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Original Poster
Rep: Reputation: 31
Thanks. I didn't know about '--'! But I figure out that I could fool 'rm' by typing path with file name which looks normal:
rm /home/mydir/--some-option
 
Old 02-15-2007, 11:07 AM   #4
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Original Poster
Rep: Reputation: 31
I check out 'man rm' and of course!!! all this is in the manual:

[HTML]
To remove a file whose name starts with a ‘-’, for example ‘-foo’, use one of these commands:
rm -- -foo
rm ./-foo
[/HTML]

Which confirms ancient wisdom: RFM!
 
Old 02-09-2010, 04:08 PM   #5
znajeeb
LQ Newbie
 
Registered: Oct 2009
Posts: 1

Rep: Reputation: 0
Remove/delete bad Linux file, having illegal character with inode

First list bad file with inode e.g.

$ ls –il
Output

14071947 -rw-r--r-- 1 znajeeb dba 0 2010-01-27 15:49 \-®Å

Note: 14071947 is inode number.

Now Use find command to delete file by inode:
$ find . -inum 14071947 -exec rm -f {} \;
It will find that bad file and will remove it with force i.e remove without prompt.
 
  


Reply

Tags
file, name, rm



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Special Characters SimeonV SUSE / openSUSE 14 07-07-2006 01:29 PM
special characters greenbox Linux - Software 9 12-23-2005 07:33 PM
File Copy Issue-Special Characters fortezza Linux - Software 1 11-14-2005 07:16 AM
Convert special characters in text file nyk Linux - Software 1 01-05-2005 03:20 PM
using special characters one_ro Mandriva 5 11-04-2004 08:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:23 AM.

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