Operating System - HP-UX
1830168 Members
5406 Online
109999 Solutions
New Discussion

How can I remove a file called -p (from touch -p)

 
SOLVED
Go to solution
michi79
Frequent Advisor

How can I remove a file called -p (from touch -p)

seems to be a unix beginners question
Ludwig Wahl
15 REPLIES 15
Victor BERRIDGE
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

Hi,
rm \-p

Best regards
melvyn burnard
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

anyother file ending in p?
ls *p
also you could try rm -i *p
and answer no to the files you do not want to remove, yes to the one you do want to remove
(if it shows up)
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Victor BERRIDGE
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

Hi,
I tried to create your case, you cannot do it with touch:
$ touch -p
touch: illegal option -- p
usage: touch [-amc] [-t [[CC]YY]MMDDhhmm[.SS] | -r ref_file] file ...
$ >-p
ll
-rw-rw-rw- 1 root sys 0 Apr 19 16:19 -p
-rw------- 1 root sys 12428 Apr 17 20:08 .ICEauthority

So to remove:
$ rm -i ./\-p
./-p: ? (y/n) y

All the best
Victor
James R. Ferguson
Acclaimed Contributor
Solution

Re: How can I remove a file called -p (from touch -p)

Hi:

Another way is this:

# rm -- -p

You can use 'touch' to create files like this by employing the same syntax:

# touch -- -p

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

Yet another option:

ls -i *p --- Find the inode # of the file

find /dir -inum inode#_of_the_file -exec rm {} \;
Tom Danzig
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

JAmes has the cleanest solution:

rm -- -p

the -- after rm indicates no more command arguments. -p will be interpreted as a filename.
Vincenzo Restuccia
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

rm -i ?p
Peggy Fong
Respected Contributor

Re: How can I remove a file called -p (from touch -p)

Hi
Had to jump in on this one. Seems like a beginners question so I check the man page and guess what I found:

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

Regards,
Peggy
federico_3
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

lists the inode number and find the one related to -p file
#ls -li
#find $DIR -type f -inum xxx -exec rm {} \;

federico
Barry O Flanagan
Respected Contributor

Re: How can I remove a file called -p (from touch -p)

...or

rm "-p"
Darren Miller
Advisor

Re: How can I remove a file called -p (from touch -p)

The rm -- -p option is correct. Here's an extra credit exercise: If a file file is created with the following command:

# touch -- '-r *'

how would you remove it? NOTE: don't try this on your production boxes ...



Peggy Fong
Respected Contributor

Re: How can I remove a file called -p (from touch -p)

You cannot create -p with touch but you can with >-p

Both commands work (say -p is in /opt):

cd /opt
rm -- -p
or
rm /opt/-p

rm -i and answering "n" to all but the one you want to remove also works but takes to long and can be dangerous (could remove wrong files).

peg
Peggy Fong
Respected Contributor

Re: How can I remove a file called -p (from touch -p)

It would be nice if you would assign points to the people who took the time to post answers to your question. There is another thread with many more answers along the same line as yours. That thread too, has no points assigned yet - hopefully the answers will help people, but with points, other sysadmins will know which answers helped out the most. Please post points.

Here's the other thread on remove files with "-" : http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x0c87dfe5920fd5118fef0090279cd0f9,00.html
michi79
Frequent Advisor

Re: How can I remove a file called -p (from touch -p)

Than you all for your help. I wanted to correct
the assign of points but this is unfortunatley
not possible

Wahl
Ludwig Wahl
Ravi_8
Honored Contributor

Re: How can I remove a file called -p (from touch -p)

Hi,
rename the file and remove
i.e # mv -p x
# rm x

never give up