views:

1083

answers:

7

Ok, I have been working with Solaris for a 10+ years, and have never seen this...

I have a directory listing which includes both a file and subdirectory with the same name:

-rw-r--r--   1 root     other    15922214 Nov 29  2006 msheehan
drwxrwxrwx  12 msheehan sysadmin    2048 Mar 25 15:39 msheehan

I use file to discover contents of the file, and I get:

bash-2.03# file msheehan
msheehan:       directory
bash-2.03# file msh*
msheehan:      ascii text
msheehan:       directory

I am not worried about the file, but I want to keep the directory, so I try rm:

bash-2.03# rm msheehan
rm: msheehan is a directory

So here is my two part question:

  1. What's up with this?
  2. How do I carefully delete the file?

Jonathan

Edit: Thanks for the answers guys, both (so far) were helpful, but piping the listing to an editor did the trick, ala:

bash-2.03# ls -l > jb.txt
bash-2.03# vi jb.txt

Which contained:

-rw-r--r--   1 root     other    15922214 Nov 29  2006 msheehab^?n
drwxrwxrwx  12 msheehan sysadmin    2048 Mar 25 15:39 msheehan

Always be careful with the backspace key!

A: 

And a quick answer to part 2 of my own question...

I would imagine I could rename the directory, delete the file, and rename the directory back to it's original again.

... I would still be interested to see what other people come up with.

JB

Jonathan Bourke
A: 

I suspect that one of them has a strange character in the name. You could try using the shell wildcard expansion to see that: type

cat msh*

and press the wildcard expansion key (in my shell it's Ctrl-X *). You should get two names listed, perhaps one of which has an escape character in it.

Anthony Williams
Good call. @Jonathan Bourke, what's a "for f in *; do echo "t${f}t";done give you?
Blair Conrad
Hmm... although the second "file" output in the question suggests that maybe this isn't the case... I'm confused.
Blair Conrad
+4  A: 

I would guess that these are in fact two different filenames that "look" the same, as the command file was able to distinguish them when the shell passed the expanded versions of the name in. Try piping ls into od or another hex/octal dump utility to see if they really have the same name, or if there are non-printing characters involved.

wnoise
+1  A: 

I'm wondering what could cause this. Aside from filesystem bugs, it could be caused by a non-ascii chararacter that got through somehow. In that case, use another language with easier string semantics to do the operation.

It would be interesting to see what would be the output of this ruby snippet:

ruby -e 'puts Dir["msheehan*"].inspect'
bltxd
No ruby installed on this server, and as it is a critical production DB system, I think I will leave it alone for the moment. Good question though, and one that has occupied my mind as well...JB
Jonathan Bourke
A: 

To see if there are special characters in your file, Try the -b or -q options to ls, assuming solaris 8 has those options.

As another solution to deleting the file you can bring up the graphical file browser (gasp!) and drag and drop the unwanted file to the trash.

Another solution might be to move the one file to a different name (the one without the unknown special character), then delete the special character directory name with wildcards.

mv msheehan temp
rm mshee*
mv temp msheehan

Of course, you want to be sure that only the file you want to delete matches the wildcard. And, for your particular case, since one was a directory and the other a file, this command might have solved it all:

rmdir msheeha*
Alan H
A: 

One quick-and-easy way to see non-printing characters and whitespace is to pipe the output through cat -vet, e.g.:

# ls -l | cat -vet

Nice and easy to remember!

TLS
A: 

For part 2, since one name contains two extra characters, you can use:

mv sheehan abc
mv sheeha??n xyz

Once you've done that, you've got sane file names again, that you can fix up as you need.

Jonathan Leffler