Operating System - HP-UX
1827249 Members
2708 Online
109716 Solutions
New Discussion

Re: delete files with filename starting with special characters

 
Davide Depaoli
Occasional Advisor

delete files with filename starting with special characters

Hi,
I've forgot how to delete files with filename starting with special characters. In particular, starting with "-" char.
thanks in advance

regards Davide
15 REPLIES 15
Alex Glennie
Honored Contributor

Re: delete files with filename starting with special characters

ll -i (to find the inode number)

substitute the inode number in place of the # below; (be very careful with the syntax, it must be exactly correct)

find . -xdev -inum # -exec ll {} \;
find . -xdev -inum # -exec rm -i {} \;
Printaporn_1
Esteemed Contributor

Re: delete files with filename starting with special characters

Hi,

You can simply specify full path to file
for example
rm /tmp/-xxx

Thanks
enjoy any little thing in my life
Thomas Kollig
Trusted Contributor

Re: delete files with filename starting with special characters

Hi!
Instead of "rm -abc" use "rm ./-abc".

Thomas
Thierry Poels_1
Honored Contributor

Re: delete files with filename starting with special characters

I you start deleting files with special characters by using wildcards I would really encourage you to use "rm -i". Play it safe!


I once saw an experienced sysadmin delete a file named "*" with "rm *". Well he succeeded, the file was gone ;)
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Bill McNAMARA_1
Honored Contributor

Re: delete files with filename starting with special characters

If your promt is in vi mode
set -o vi
You can use the quote
rm "
then ESC
the cursor will move back a space
then =
to get a list of the files
You can then type the first letter
and ESC ESC to get the shell to
continue the file name.
This is real usefull for strange characters
at the end of the filename as well.

I recall once that some of these files with special characters don't show up on a quota?
Although I could be wrong about that.

Bill
It works for me (tm)
Thierry Poels_1
Honored Contributor

Re: delete files with filename starting with special characters

hey, where is my reply ???
OK, second try :


When deleting files with special characters by using wildcards I would really encourage you to use "rm -i". Play is safe!

I one saw an experience sysadmin delete a file named "*" with "rm *". Well he succeeded, the file was gone ;)

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
CHRIS_ANORUO
Honored Contributor

Re: delete files with filename starting with special characters

Hello Davide,

Thierry is right, play it safe use "rm -i *". This will help you on delete the file using interactive mode of yes/no. You just have to be careful in using the command.
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Paula J Frazer-Campbell
Honored Contributor

Re: delete files with filename starting with special characters

Hi
How about deleting a file "-R*" in the / dir ?
People will try to catch you out so -i should become a habit.

Paula
If you can spell SysAdmin then you is one - anon
Mark Mitchell
Trusted Contributor

Re: delete files with filename starting with special characters

Before you delete anything. First rename the file with a mv command. Then delete the file specifically.
Bill McNAMARA_1
Honored Contributor

Re: delete files with filename starting with special characters

You can use a \ to remove the special meaning in between the " .. but yea do it the way the others suggest.

Later,
Bill
It works for me (tm)
Volker Borowski
Honored Contributor

Re: delete files with filename starting with special characters

Hello,

never deal with wildcards in this case !
Use "ftp localhost" and delete by exactly
typing the name. ftp does not expand wildcards.

Volker
Gregory Fruth
Esteemed Contributor

Re: delete files with filename starting with special characters

If the special character is '-', then the simplest way to
refer to it is to use the "--" option, which most commands
support (see "man 3 getopt"). To delete a file called '-i',
you'd say "rm -- -i". The "--" option tells the command
that all subsequent arguments are filenames and not
options.

For other shell special characters like '*', '$', '!', ' ' (space),
etc., just enclose the filename in single quotes; the "--"
and "./" techniques won't work for that.
Nick D'Angelo
Super Advisor

Re: delete files with filename starting with special characters

Davide,

Ciao, scuzzarmi di mia scriatura.

Begoigno di dari punti a le resposto che tutti di addatto.

Grazie,

Nickd
_____
Translation
Hello,

Pardon my Italian writing.

One should assign points or review replies that everyone posts to your question.

Thank you.
Always learning
Rob Smith
Respected Contributor

Re: delete files with filename starting with special characters

Hi, first of all, not trying to mooch points but you can just use rm -- "file" Example rm -- -r. Secondly, a lot of people took the time to answer your query, don't you think it is fair that you assign them some points. Hope this helps.

Rob

Learn the rules so you can break them properly.
Peggy Fong
Respected Contributor

Re: delete files with filename starting with special characters

Interesting, there was a similar thread on 4/20 by Wahl with answers on how to remove a file called -p where no points were assigned to anyone there either. Here's the thread:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xa78d0cb17a32d5118fef0090279cd0f9,00.html

Too bad people aren't assigning points...we're going to lose the value of this site.