Operating System - HP-UX
1837139 Members
2249 Online
110112 Solutions
New Discussion

How to remove a file which has starts with - (minus/dash) character

 
SOLVED
Go to solution
John Hickey_1
New Member

How to remove a file which has starts with - (minus/dash) character

How do I remove a file which starts with a - (minus/dash) character?

eg. filename is -t
Have tried rm "-t", rm '-t' rm -t
All give an error message, because it thinks that the dash is a opt/arg flag

Have also tried considered using rm ?t but when doing ls ?t, the wildcard expansion does not seem to be working correctly
10 REPLIES 10
Andreas Voss
Honored Contributor
Solution

Re: How to remove a file which has starts with - (minus/dash) character

Hi,

simly type:
rm ./-t

Cheers

Andrew
Danny Engelbarts
Frequent Advisor

Re: How to remove a file which has starts with - (minus/dash) character

John,

try a rm -t

this works on most "weird" characters in filenames (like * spaces tabs or control chars)

Greetz, Danny.
Stefan Farrelly
Honored Contributor

Re: How to remove a file which has starts with - (minus/dash) character


or use;

rm -- -t
Im from Palmerston North, New Zealand, but somehow ended up in London...
John Palmer
Honored Contributor

Re: How to remove a file which has starts with - (minus/dash) character

The easiest way is to use the '--' construct to say that the list of options is complete:-

rm -- -t
Danny Engelbarts
Frequent Advisor

Re: How to remove a file which has starts with - (minus/dash) character



oookay ... the backslash i typed doesn't show up [sigh] so that was;

rm [backslash]-t

Greetz, Danny.
Kofi ARTHIABAH
Honored Contributor

Re: How to remove a file which has starts with - (minus/dash) character

John:

this question had been answered earlier in the forum... you would have to do:

rm -- -t

cheers.
nothing wrong with me that a few lines of code cannot fix!
Andreas Voss
Honored Contributor

Re: How to remove a file which has starts with - (minus/dash) character

Just a hint for Danny:
If you want to post the backslash in your reply type it twice :-)
Rita C Workman
Honored Contributor

Re: How to remove a file which has starts with - (minus/dash) character

Here's another little tip...removing files using the instance number, when you can't remove it with normal rm commands. It is something you would need to be very
careful doing ! But here it is:

cd to where the file is located and type: ls -i

This will list the files with their corresponding instance number. Now just do a find from where you are and execute the remove for that instance number

find . -inum -exec rm {} \;

Just a thought,
John Hickey_1
New Member

Re: How to remove a file which has starts with - (minus/dash) character

Thanks to all for quick responses.

Note that rm \-t does not work, but rm .\-t does work
(not sure why)
Kofi ARTHIABAH
Honored Contributor

Re: How to remove a file which has starts with - (minus/dash) character