Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File won't Delete and appears with LS but not DIR

Status
Not open for further replies.

dman7777777

IS-IT--Management
Jan 13, 2007
52
US
There were two files with the same filename that I created. One was 0 bytes and the other had like 3642 bytes. I tried to cat the file but it wouldn't. So I deleted the file. Afterwards, the file with 0 bytes was gone but the file that actually had bytes still remained. I tried to delete that file but it said the file didn't exist. Yet it appears when I do a LS but not DIR. How can I get rid of it and what is wrong?

 
First I think you need to run ls -lba on the directory to check for any unprintable characters in the name
 
You can also have space or tab character(s) at the end of the filename. An ls -lba wont show/highlight spaces, but it will show tabs as \011 though.

to find spaces in filenames:

[tt]for i in *
do
echo "'$i'"
done[/tt]

You can use something other than just * to limit the number of generated names. E.g. if the filename starts with 'a':

[tt]for i in a*
do
echo "'$i'"
done[/tt]


HTH,

p5wizard
 
I think I did a backspace when I typed in the filename of the application I was running that wrote it. I did a ls -lba but it didn't show the file. How can I get rid of it?

 
Try finding the inode number (ls -i), then do a find to delete that:

find . -inum [number] -exec rm {} \;

You might try an ls {} first to be sure you're picking up the correct file.


I want to be good, is that not enough?
 
I found it with ls -i! Can I just do a rm and the node number? I feel funny executing that other code because it's a live system and I don't want to mess up anything.
 
You can't delete the node number using rm unless you use the find command!

Have you tried the other alternatives in the link above?

Regards,
Khalid
 
man rm, but no, so it looks as though the find is the best option - as I say try

find . -inum [number] -exec ls {} \;

to make sure you're getting the correct file before using rm on it.

I want to be good, is that not enough?
 
KenCunningham I think we are sharing the thoughts at exactly the same time :)
 
Certainly seems that way Khalid - as long as we agree, everything should be fine!

I want to be good, is that not enough?
 
Thanks guys for your help! That works on my own personal AIX shell. I'm still scared to use it on the system at work though. Maybe I will.
 
Use rm -i {} and it will prompt you if you want to remove it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top