15

So somehow the command ls seems to be showing me two identical files in a directory.

$ ls -Blah /System/Library/LaunchDaemons
total 32                                                              
drwxr-xr-x  266 root  wheel   8.8K Jun 18 10:41 .
drwxr-xr-x   79 root  wheel   2.6K Mar 31 12:28 ..
[redacted]
-rw-r--r--    1 root  wheel   715B Jun 18 10:36 tftp.plist
-rw-r--r--    1 root  wheel   715B Jun 18 10:35 tftp.plist

I can move, rename, edit etc. one of the files, but the other one does not even seem to be there. bash tab completion even shows identical files.

For example, entering the following and then hitting TAB

$ sudo mv /System/Library/LaunchDaemons/tftp
tftp.plist   tftp.plist

If I rename the file:

$ sudo mv /System/Library/LaunchDaemons/tftp.plist /System/Library/LaunchDaemons/tftp.plist.derp

The tab completion still shows the file:

$ ls -Blah /System/Library/LaunchDaemons/tf
tftp.plist       tftp.plist.derp 

But the original, unmodified file does not appear to 'ls'

$ ls -Blah /System/Library/LaunchDaemons/tftp.plist
ls: /System/Library/LaunchDaemons/tftp.plist: No such file or directory

However if I just list the files as in the first code snippet above, behold:

$ ls -Blah /System/Library/LaunchDaemons
total 32                                                              
drwxr-xr-x  266 root  wheel   8.8K Jun 18 10:41 .
drwxr-xr-x   79 root  wheel   2.6K Mar 31 12:28 ..
[redacted]
-rw-r--r--    1 root  wheel   715B Jun 18 10:35 tftp.plist
-rw-r--r--    1 root  wheel   715B Jun 18 10:36 tftp.plist.derp

Any idea what's going on here and how I can get rid of this ghost file?

This is a mac running OS X if that adds any info to the problem. I was using sed on this file just before the craziness began.

Edit

I have used both the blah and the Blah ls flags with no change in apparent output.

Edit 2

Additional info requested in comments:

$ echo tftp* | xxd
0000000: 7466 7470 2e70 6c69 7374 2020 7466 7470  tftp.plist  tftp
0000010: 2e70 6c69 7374 2e64 6572 700a            .plist.derp.

More:

$ printf '<%q>\n' tftp*
<tftp.plist\ >
<tftp.plist.derp>

Even more:

$ locale                                                                                                                      │-rw-r--r--    1 root  wheel   495B Sep  9  2014 org.net-snmp.snmpd.plist
LANG="en_US.UTF-8"                                                                                                            │-rw-r--r--    1 root  wheel   498B Jan 15 23:15 org.ntp.ntpd.plist
LC_COLLATE="en_US.UTF-8"                                                                                                      │-rw-r--r--    1 root  wheel   1.0K Nov 13  2014 org.openldap.slapd.plist
LC_CTYPE="en_US.UTF-8"                                                                                                        │-rw-r--r--    1 root  wheel   572B Sep  9  2014 org.postfix.master.plist
LC_MESSAGES="en_US.UTF-8"                                                                                                     │-rw-r--r--    1 root  wheel   238B Sep  9  2014 shell.plist
LC_MONETARY="en_US.UTF-8"                                                                                                     │-rw-r--r--    1 root  wheel   941B Sep  9  2014 ssh.plist
LC_NUMERIC="en_US.UTF-8"                                                                                                      │-rw-r--r--    1 root  wheel   260B Sep  9  2014 telnet.plist
LC_TIME="en_US.UTF-8"                                                                                                         │-rw-r--r--    1 root  wheel   715B Jun 18 10:36 tftp.plist
LC_ALL="en_US.UTF-8"

Note

The answer below helped me see that there was a trailing space in the name.

12
  • 6
    Could it be that you have a trailing space in the name? Jun 18 '15 at 15:12
  • Hmmm… No, completion will do ls test\ … What happen if you use ls "*tftp.list*"? or use ls with --show-control-chars? Jun 18 '15 at 15:13
  • 1
    Can you run something like echo tftp* | xxd or some other hexdump?
    – choroba
    Jun 18 '15 at 15:16
  • 2
    What's the output of printf '<%q>\n' tftp*?
    – Chris Down
    Jun 18 '15 at 15:23
  • 3
    Since your locale is en_US.UTF-8, ls -b will not show blanks in filenames in any special way, whether in the middle or at the end of the filename. You can use one of the answers (printf, echo), or filter ls's output with a program designed to highlight trailing blanks such as ls -1 tftp* | cat -vet Jun 19 '15 at 13:49
23

You either have trailing whitespace, or a corrupt filesystem.

Try

for i in tftp.plist*
do
    echo "'$i'"
done

That should output something like

'tftp.plist'
'tftp.plist '

note the quotes and the extra space. If it outputs the exact same thing twice, you likely have a corrupt filesystem.

Try

ls -i tftp.plist*

this will give you the inode numbers of the file. If they're the same, you have the same file twice in your directory. That would be Really Bad(tm), and you should run fsck asap. But I doubt that's the problem; it's more likely the whitespace thing.

7
  • Any idea why the trailing whitespace was not showing up using the b or B flags with 'ls`?
    – 111---
    Jun 18 '15 at 17:01
  • @datUser: -B is nothing to do with this, and you don't show an example of ls -b. However, with -blah you certainly should have seen a line ending tftp.plist\ Jun 18 '15 at 17:34
  • Yeah i was using both b and B and neither show the escaped space or the value of the non-printing character in readable format. Very odd IMHO.
    – 111---
    Jun 18 '15 at 17:40
  • 1
    You can redirect the output of ls into a file, and check it with less or a text editor... Jun 18 '15 at 19:23
  • 1
    For those still wondering, the hexdump reveals the name is "tftp.plist " (that is, trailing space).
    – Joshua
    Jun 18 '15 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.