File and directory with the same name in the same parent directory - Solaris 8, ufs

Ok, I’ve been working with Solaris for over 10 years and have never seen this ...

I have a list of directories that includes both a file and a 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 the file to detect the 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 save the directory, so I will try rm:

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

So here is my two-part question:

  • What's up with that?
  • How can I delete a file?

Jonathan

Edit: Thanks for the answers, guys, both (so far) have been helpful, but sending the list to the editor did the trick, ala:

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

What 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!

+4
source share
8 answers

I would suggest that these are actually two different file names that “look” the same, since the batch file was able to distinguish them when the shell passed extended versions of the name. Try plugging ls in od or another hex / octal dump to see if they really have the same name, or if there are non-printable characters.

+6
source

I wonder what might cause this. Besides file system errors, this could be caused by a non-ascii character that somehow went through. In this case, use another language with simpler semantics to perform the operation.

It would be interesting to see what the output of this ruby ​​fragment will be:

 ruby -e 'puts Dir["msheehan*"].inspect' 
+1
source

You can delete using 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 have an example (in Spanish) how you can delete a file using iNode in Solaris http://sparcki.blogspot.com/2010/03/como-eliminar-archivos-utilizando-su.html

Urko,

+1
source

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

I would suggest that I could rename the directory, delete the file, and rename the directory back to it again.

... I still would be interested to know what other people came up with.

Jb

0
source

I suspect one of them has a strange character in the name. You can try using the shell expansion extension to see the following: type

 cat msh* 

and press the expansion expansion key (in my shell this is Ctrl-X *). You must specify two names, perhaps one of them has an escape character in it.

0
source

To find out if your file has special characters, try the -b or -q options for ls if Solaris 8 has such options.

As another solution to delete a file, you can call up the graphical file browser (gasp!) And drag the unwanted file into the trash.

Another solution would be to move one file to another name (one without an unknown special character), and then delete the special character catalog name using 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 pattern. And for your specific case, since one of them was a directory and the other a file, this command could solve all this:

 rmdir msheeha* 
0
source

One quick and easy way to view non-printable characters and spaces is to output the results via cat -vet, for example:

  # ls -l |  cat -vet

Nice and easy to remember!

0
source

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

 mv sheehan abc mv sheeha??n xyz 

After you have done this, you again have the correct file names, which you can fix as you need.

0
source

Source: https://habr.com/ru/post/1276807/


All Articles