Operating System - HP-UX
1837533 Members
3666 Online
110117 Solutions
New Discussion

How to rm a file called "-I"

 
Craig A. Sharp
Super Advisor

How to rm a file called "-I"

I know, its a strange question. But how do I do it. rm is seeing the name as a switch.

Thanks,

Craig
8 REPLIES 8
A. Clay Stephenson
Acclaimed Contributor

Re: How to rm a file called "-I"

Getopts has the convention that "--" means no more arguments follow; so:

rm -- -l
If it ain't broke, I can fix that.
John Dvorchak
Honored Contributor

Re: How to rm a file called "-I"

Age old problem. Or if the file name is unprintable characters. The recomended way is to ls -i which will give you the inode number of the file then do a find and -exec rm -i :

root> ls -i

12345 -lfile

root> find . -inum 12345 -exec rm -i {} \;

Then it will prompt you to remove the file.


If it has wheels or a skirt, you can't afford it.
Jeff_Traigle
Honored Contributor

Re: How to rm a file called "-I"

Or "rm ./-l"

There is an example of this very problem in the rm man page.
--
Jeff Traigle
Sandman!
Honored Contributor

Re: How to rm a file called "-I"

cd to the folder containing the file and do a...

# rm -i

...then answer "y" only when it prompts you for the file in question i.e. "-l"

cheers!
Arturo Galbiati
Esteemed Contributor

Re: How to rm a file called "-I"

Hi,
rm -- "-i"

HTH,
Art
Muthukumar_5
Honored Contributor

Re: How to rm a file called "-I"

simply as,

# rm ./-I

or

# rm -- -I

# rm /-I

--
Muthu
Easy to suggest when don't know about the problem!
Yogeeraj_1
Honored Contributor

Re: How to rm a file called "-I"

hi craig,

being more cautious, i would do a mv first then proceed with the delete.

mv -- -l l
rm l

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Geoff Wild
Honored Contributor

Re: How to rm a file called "-I"

Also see:

http://www.helpdesk.umd.edu/topics/troubleshooting/os/unix/1231/

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.