Operating System - HP-UX
1832877 Members
2302 Online
110048 Solutions
New Discussion

Re: How to remove a file "-1" ?

 
Hans-Joerg Herrmann
New Member

How to remove a file "-1" ?

I found a file with the name "-1". Has anybody an idea how to delete it. rm interprets the "-" as an option. Also rm -i *1 doesn't work (hp-ux 10.20).
Joerg
11 REPLIES 11
Thierry Poels_1
Honored Contributor

Re: How to remove a file "-1" ?

hi,

directly from the man page:
Remove a file in the current directory whose name starts with - or *
or some other character that is special to the shell:

rm ./-filename
rm \*filename


good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Sergejs Svitnevs
Honored Contributor

Re: How to remove a file "-1" ?

Specify full path to file:
Example:
rm -i /var/adm/-1

Regards,
Sergejs
john korterman
Honored Contributor

Re: How to remove a file "-1" ?

Hi,
you can also do this:
# rm -- -1

If you want to try other possibilities, you can always create the file again like this:
# touch -- -1

regards,
John K.
it would be nice if you always got a second chance
Armin Feller
Honored Contributor

Re: How to remove a file "-1" ?

Hi,

use the inode to remove the file:

# ll -i
# find -inum -exec rm -f {} \;

e.g.
# ll -i
6933 -rwxrwxr-- 1 root sys 621 Mar 6 09:14 -1
# find . -inum 6933 -exec rm -f {} \;

Regards ...
Armin
David_246
Trusted Contributor

Re: How to remove a file "-1" ?

Hi,

I would had to think again, but these are indeed the funny ones.

always use a rm -i on these files. In case of your file use :

rm -i -- -1

in other cases "rm -i *file" will work, also when a ^H or so is added use a "ls | od -c" to view what character is used. ls >/tmp/1, leave only the to be deleted file in and do :
for i in `cat /tmp/1`
do
rm $i
done

Good luck.
Regs David
@yourservice
V. V. Ravi Kumar_1
Respected Contributor

Re: How to remove a file "-1" ?

hi,

rm -i -- -1

or
ll -i in that dir, note inum of file -1
then
find . -inum -exev rm -f {} \;

Regards
Never Say No
Frederic Sevestre
Honored Contributor

Re: How to remove a file "-1" ?

Hi,

Try find . -name "*-1*" -exec rm {} \;

Regards,
Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
Ernesto Cappello
Trusted Contributor

Re: How to remove a file "-1" ?

Hi
You perform this command:

# rm -i *

and later, with a lot of caution, you choose whether to remove (with "y").

Regards.
Ernesto.
Frank Slootweg
Honored Contributor

Re: How to remove a file "-1" ?

rm ./-1
Christoph Rothe_3
Frequent Advisor

Re: How to remove a file "-1" ?

Or using perl:

perl -e "unlink \"-1\""

Christoph
T G Manikandan
Honored Contributor

Re: How to remove a file "-1" ?

#rm -- -1

or
rm -i ./-1