Operating System - HP-UX
1829331 Members
2046 Online
109989 Solutions
New Discussion

How to remove files with '-' as the first character of a file name?

 
SOLVED
Go to solution
Kelvin Yu
Advisor

How to remove files with '-' as the first character of a file name?

Hi,

I would like to remove some obsolete files which were created with '-' as the first character of a file name. I guessed those files were created by mistake. As you can see,
#rm -filename
is not valid because there is '-' in the front. Any help appreciated. Thanks.

Regards,
Kelvin
6 REPLIES 6
Robert-Jan Goossens_1
Honored Contributor

Re: How to remove files with '-' as the first character of a file name?

Hi Kelvin

# rm -- -filename

the -- will discard any option of thr rm command.

Regards,
Robert-Jan
Pete Randall
Outstanding Contributor

Re: How to remove files with '-' as the first character of a file name?

Kelvin,

You can also use "rm ./-filename".


Pete

Pete
Jairo Campana
Trusted Contributor
Solution

Re: How to remove files with '-' as the first character of a file name?

example:

>tes||% (file with characters special)
ls -lia
159518 -rw-r--r-- 1 root other 0 Nov 18 10:53 test%

find . -inum 159518 -exec rm {} \;

%(charater special -,&$"·$!$
legionx
Geoff Wild
Honored Contributor

Re: How to remove files with '-' as the first character of a file name?

Check out this page:

http://unix.t-a-y-l-o-r.com/UMstrange.html

Files that begin with a dash can be removed by typing

rm ./-filename


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.
hpuxrox
Respected Contributor

Re: How to remove files with '-' as the first character of a file name?

I sometimes put files like that in single quotes

rm '-filename'

That usualy works most of the time, unless you have a file like G$'5;ds!@. Then you will need to use the find option give above.
Kelvin Yu
Advisor

Re: How to remove files with '-' as the first character of a file name?

I found the answer. Thanks so much.