Operating System - HP-UX
1832541 Members
5340 Online
110043 Solutions
New Discussion

removing a file that starts with "-"

 
SOLVED
Go to solution
John Downs_1
Frequent Advisor

removing a file that starts with "-"



One of my users created a file called "-h".
When I try to rm it i get, -h unknown option.
I've tried \-h "-h" and single quotes to no avail. Help!

-john
I'd rather be fly fishing for trout!
11 REPLIES 11
S.K. Chan
Honored Contributor
Solution

Re: removing a file that starts with "-"

One way is to list it with its inode number and then use find to remove it.
# cd
# ls -i
==> Take note of its inode number. Then run ..
# find . -inum -exec rm -f {} \;
Kellogg Unix Team
Trusted Contributor

Re: removing a file that starts with "-"

rm ./-h

will do.

...Manjeet
work is fun ! (my manager is standing behind me!!)
James R. Ferguson
Acclaimed Contributor

Re: removing a file that starts with "-"

Hi John:

Try:

# rm -i "*-h*"

...and respond yes or no appropriately.

Regards!

...JRF...
Domenico_5
Respected Contributor

Re: removing a file that starts with "-"

use file manager from x terminal
Jean-Luc Oudart
Honored Contributor

Re: removing a file that starts with "-"

and finally you may want to see the content of the file before you delete it ?
more -- -h
or rename it
mv -- -h newfilename

Jean-Luc
fiat lux
Domenico_5
Respected Contributor

Re: removing a file that starts with "-"

hei guys!!!!!

4 answer, 4 correct answer and all different!!!!!!!!!!!

goood!!!!
James R. Ferguson
Acclaimed Contributor

Re: removing a file that starts with "-"

Hi (again):

# rm -i -- -h

Regards!

...JRF...
John Palmer
Honored Contributor

Re: removing a file that starts with "-"

And a fifth...

rm -- -h

Regards,
John
Domenico_5
Respected Contributor

Re: removing a file that starts with "-"

john

A strawberry on a pie
John Downs_1
Frequent Advisor

Re: removing a file that starts with "-"


Well, either you guys have been doing this to long or i haven't been doing it long enough.
I tried rm ./-h, fewest charaters to type, and it worked. The next time I'll one of the other solutions.

Thanks!

-john
I'd rather be fly fishing for trout!
James R. Ferguson
Acclaimed Contributor

Re: removing a file that starts with "-"

Hi (again) John:

/No_Points_Please/

I'm not sure what the h*ll I was thinking with my first suggestion of "*-h*" but that clearly wonn't work! Fortunately my second offering was correct and preferred and you gave me points for that! For future readers:

In general, two consecutive hyphens single the end of flags for well-behaved commands. At your leisure:

# touch -- -h
# ls -- -h
# mv -- -h -hh
# ls -- -h
# ls -- -h*
# set -f #...disable globbing...
# ls -- -h*
# set +f #...enable globbing...
# rm -i -- -h*

Regards!

...JRF...