System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Delete file with "-" character inside its name

SOLVED
Go to solution
Tonatiuh
Super Advisor

Delete file with "-" character inside its name

Red Hat Linux 3

I have (by accident) a file which name is:

-stats.tar.gz

How can I delete this file?
5 REPLIES
Ivan Ferreira
Honored Contributor
Solution

Re: Delete file with "-" character inside its name

rm -- -stats.tar.gz
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Oviwan
Honored Contributor

Re: Delete file with "-" character inside its name

Hey

try to escape the - char, like this:
#rm \-stats.tar.gz

Regards
Tonatiuh
Super Advisor

Re: Delete file with "-" character inside its name

Escaping character did not work. Ivan's solution was good.

Thank you to both.
Yogeeraj_1
Honored Contributor

Re: Delete file with "-" character inside its name

hi,

this would be another option:
find . -name "-test" -exec rm {} \;

e.g.
[root@server1 tmp]# cat /etc/hosts > '-test'
[root@server1 tmp]# ls
EM_TARGET_INSTALLER.lk ibm p2617419_10102_generic.zip -test tx.log
[root@server1 tmp]# find . -name "-test" -exec rm {} \;
[root@server1 tmp]# ls
EM_TARGET_INSTALLER.lk hp p2617419_10102_generic.zip tx.log
[root@server1 tmp]#

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

Re: Delete file with "-" character inside its name

> this would be another option:
> find . -name "-test" -exec rm {} \;

And if you have a file like "./fred/-test",
and you don't want to delete _that_ one?

An unrestricted "find" is a pretty big hammer.