1827808 Members
12849 Online
109969 Solutions
New Discussion

Delete a file

 
SOLVED
Go to solution
Mark Brook
Frequent Advisor

Delete a file

I have somehow managed to create a file on our unix box without a filename. So when you list the files in the directory you get the following

file123

file124

How can I remove a file, without a filename?

Thanks

Mark
8 REPLIES 8
john korterman
Honored Contributor
Solution

Re: Delete a file

Hi,
tricky if the file has no name. Try to execute ls -b and show us what appears.

regards,
John K

it would be nice if you always got a second chance
RAC_1
Honored Contributor

Re: Delete a file

ls -lbi

note down inode no.

then

find . -num inode_no -exec rm -fr {} \;

There is no substitute to HARDWORK
Mark Brook
Frequent Advisor

Re: Delete a file

I have done the ls -lbi and the filename is \ma123.

Wasnt sure about using the find then rm options, since I read what -rf does.

Can you remove the file using the id number?

Thanks

Mark
john korterman
Honored Contributor

Re: Delete a file

Hi again,
as RAC says, use the inode number for removing the file. The inode number is the number appearing left of the filename when executing ls -bi. It should be enough if you just do this:
# cd to the right directory
# find . -inum -exec rm {} \;

which will remove the file having and nothing else.
It is important to be in the right directory as the inode numbers are only unique within each filesystem!

but it is perhaps a good idea to touch another file (with a name) and practice on that first.

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

Re: Delete a file

Nope

You need the file name

HTH

Ste
take your time and think things through
A. Clay Stephenson
Acclaimed Contributor

Re: Delete a file

No, rm will not use inode numbers. You coulkd use the find ... -exec rm {} \; without the fr options if it will make you feel better.

Another option is to use the interactive version of rm:

rm -i *a123

That will prompt you for a y/n for each file matching the pattern. As soon as you see your file, answer y to delete it and then you can ctrl-c (or whatever your INTR is set to) to end the rm command.
If it ain't broke, I can fix that.
lawrenzo
Trusted Contributor

Re: Delete a file

what if you used rm -i *
hello
Vitek Pepas
Valued Contributor

Re: Delete a file

Try this:
ls > list.txt
then vi list.txt and remove all lines except of your 'blank' filename, then
rm `cat list.txt`