Operating System - HP-UX
1826861 Members
3008 Online
109705 Solutions
New Discussion

weird file - can't be deleted....

 
SOLVED
Go to solution
Christina Martin
Frequent Advisor

weird file - can't be deleted....

-rw-rw-r-- 2 root AJP 92 Sep 1 00:00 ---
-rw-rw-rw- 2 root AJP 648605 Sep 7 01:00 35010000.07
-rw-rw-rw- 2 root AJP 8792777 Sep 10 01:04 35010000.10
-rw-rw-rw- 2 root AJP 11055850 Aug 29 01:04 35010000.29

The first 2 lines show --- as the file name.
when I do a ls -lab it still shows --- as the file name.

I tried an rm -i * to remove the file, I get illegal option.

I tried redirecting the directory list to a file and creating a shell to remove the file, same result, illegal option.

Does anyone have any idea how to remove this file without having to copy the required information into another directory and deleting the entire directory that this resides in? (Not even sure if that would work).

Thanks
Lisa Taylor
14 REPLIES 14
Alan Meyer_4
Respected Contributor

Re: weird file - can't be deleted....

do an ls -i to display the inode of the file.

Then do a find . -inum n -exec rm {} \; to remove the file.
" I may not be certified, but I am certifiable... "
James R. Ferguson
Acclaimed Contributor

Re: weird file - can't be deleted....

Hi:

The easy way to remove a file named "--" is to tell 'rm' that the hypehen is NOT one of its options:

# rm -i - --

Note the "-" says that there are no more options (flags) on the commandline.

Regards!

...JRF...
TwoProc
Honored Contributor
Solution

Re: weird file - can't be deleted....

This one works pretty well to get your "rm -i" command to work:

rm -i - ./*

But, unless the list of files in the current directory is short - the approach using the inode number (first reply posting) is the one I like best for very tricky items.
We are the people our parents warned us about --Jimmy Buffett
Mei Jiao
Respected Contributor

Re: weird file - can't be deleted....

Hi Lisa,

I also find that if you specify the path (either full path of relative path) with double quotes "", it'll work:

# rm "/
Hope it helps too.

Best regards,
Mei
Vibhor Kumar Agarwal
Esteemed Contributor

Re: weird file - can't be deleted....

Try this option also:

ls -l | awk '{ if (NR==1) print rm $NF }' | sh
Vibhor Kumar Agarwal
Adisuria Wangsadinata_1
Honored Contributor

Re: weird file - can't be deleted....

Hi Lisa,

Check this document below (docID : KBRC00000429) about 'Remove File with Special Character in the Name' :

http://www2.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000080078334

Hope this info can help you to resolve the problem.

Cheers,
AW
now working, next not working ... that's unix
Matthew_50
Valued Contributor

Re: weird file - can't be deleted....

# remove it using following.
rm -- ---

The key part is the file name,
which is leading with "-".
The "-" character is collision with
unix command option "-".
we can use "--" to void the options.
Marcel Boogert_1
Trusted Contributor

Re: weird file - can't be deleted....

Hi,

You can also use an FTP program to handle your deletion request.

If you've got a MSWin client you can us wsftp or something to delete the file.

It works pretty good and the FTP program handles the special characters.


Regards, MB.
Muthukumar_5
Honored Contributor

Re: weird file - can't be deleted....

Simply as,

rm -f ./---

or

rm -f /---

or

rm -- ---

where -- used to show that getopts() argument to ls binary is completed.

hth.
Easy to suggest when don't know about the problem!
Raj D.
Honored Contributor

Re: weird file - can't be deleted....

Hi Lisa ,

Try with find

# cd /yourdir
# ls -i # ( note down the inode number of the file want to delete)
# find . -inum NNN -exec rm {} \; [where NNN is inode number ]

hope this will work ,

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Muthukumar_5
Honored Contributor

Re: weird file - can't be deleted....

You can also simply use as,

find . -name "-*" -exec rm -i {} \+

hth.
Easy to suggest when don't know about the problem!
Geoff Wild
Honored Contributor

Re: weird file - can't be deleted....

And yet another good web site with information on this topic:

http://www.helpdesk.umd.edu/topics/troubleshooting/os/unix/1231/

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.
Christina Martin
Frequent Advisor

Re: weird file - can't be deleted....

Thank you all. What I used was

rm -- --- and it worked perfectly!


Thanks again. I knew I'd get some great answers here. I've printed everything off so that I can play with these techniques and become familiar with them.
Bill Hassell
Honored Contributor

Re: weird file - can't be deleted....

One additional technique: ls/ll have a nifty option to show non-displayable characters. If you use ll -b, you'll see any special characters that may be imbedded. Note also that you may have special characters imbedded in the name such as ;[]{}\|"'<>?#~` which must be escaped with '...' or you might even have a space in the middle (or all spaces). To see special characters and spaces, you can list files something like this:

ll -b | awk '{print "\""$NF"\""}'

Now all thje filenames are surrounded by quotes so you can see leading and trailing spaces.


Bill Hassell, sysadmin