Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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'

You can delete using the iNode

If you use the "-i" option in "ls"

$ ls -li
total 1
20801 -rw-r--r-- 1 root root 0 2010-11-08 01:55 a?
20802 -rw-r--r-- 1 root root 0 2010-11-08 01:55 a\?
$ find . -inum 20802 -exec rm {} \;
$ ls -li
total 1
20801 -rw-r--r-- 1 root root 0 2010-11-08 01:55 a?

I've an example (in Spanish) how you can delete a file using then iNode on Solaris http://sparcki.blogspot.com/2010/03/como-eliminar-archivos-utilizando-su.html

Urko,

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

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.

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*

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!

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top