ls : short and slightly odd (bit like me)… .

A collegue pings me this morning to say he is having a bit of an odd time with a script erroring out, no problem I think. This is the simplified version as in the setup we saw this we had long paths and remote filesystems to lure us down blind alleys of permissions etc. We look at the log and it says (rebuilt a dummy setup of a layout that will show the issue so ignore the 0 file sizes) :

FATAL: No such file or directory opening: < /home/tig/test/1043_states.txt
Bit obvious I thought, and then it gets odd, he then runs :

ls /home/tig/test/1043_states.txt
ls: cannot access /home/tig/test/1043_states.txt: No such file or directory

Makes sense

tig@ubuntu:~/test$ ls -la
total 0
drwxr-xr-x 6 tig tig 592 2011-01-27 10:08 .
drwxr-xr-x 6 tig tig 856 2011-01-27 10:07 ..
drwxr-xr-x 2 tig tig 160 2011-01-27 10:07 1031_001
drwxr-xr-x 2 tig tig 160 2011-01-27 10:07 1033_001
drwxr-xr-x 2 tig tig 232 2011-01-27 10:09 1043_001
-rw-r--r-- 1 tig tig 0 2011-01-27 10:08 1043.bar
-rw-r--r-- 1 tig tig 0 2011-01-27 10:08 1043.foo
drwxr-xr-x 2 tig tig 160 2011-01-27 10:08 2057_002

All looks fine, the file is just not there, but he then says, "if I do" :

tig@ubuntu:~/test$ ls -la /home/tig/test/1043_*
total 0
drwxr-xr-x 2 tig tig 232 2011-01-27 10:09 .
drwxr-xr-x 6 tig tig 592 2011-01-27 10:08 ..
-rw-r--r-- 1 tig tig 0 2011-01-27 10:09 1043_state.txt

Pardon? wtf did that come from? He then did :

tig@ubuntu:~/test$ ls /home/tig/test/*.txt
ls: cannot access /home/tig/test/*.txt: No such file or directory

ls, bless it's little cotton socks has been helpful... it was only when I did (note I removed the underscore) :
tig@ubuntu:~/test$ ls /home/tig/test/1043*
/home/tig/test/1043.bar /home/tig/test/1043.foo

/home/tig/test/1043_001:
1043_state.txt

Do we see what is going on, ls matched the 1043_ with the 1043_001 directory and then hides it and shows you the matching result from within it, if only seems to be if there is a match in the current directory (or more than one matching directory) does it actually tell you the directory it is in...

All this before I had chance to put the kettle on...