What is the difference between 'ls *.py" and "ls *py"?

1

This happens in cygwin (CYGWIN_NT-5.1 MYPC 1.7.5(0.225/5/3) 2010-04-12 19:07 i686 Cygwin)

First command, ls *.py shows nothing

$ ls *.py
ls: cannot access *.py: No such file or directory

First command, ls *.py runs in the same location, shows the following

$ ls *py
LICENSE.txt    _cpchecker.pyc   _cperror.pyc    _cpserver.py          _cptree.pyc         favicon.ico
__init__.py    _cpconfig.py     _cplogging.py   _cpserver.pyc         _cpwsgi.py          lib
__init__.pyc   _cpconfig.pyc    _cplogging.pyc  _cpthreadinglocal.py  _cpwsgi.pyc         process
_cpcgifs.py    _cpdispatch.py   _cpmodpy.py     _cptools.py           _cpwsgi_server.py   scaffold
_cpcgifs.pyc   _cpdispatch.pyc  _cprequest.py   _cptools.pyc          _cpwsgi_server.pyc  wsgiserver
_cpchecker.py  _cperror.py      _cprequest.pyc  _cptree.py            cherryd

These are files in a subdirectory cherrypy

I did not alias ls in any way (running /usr/bin/ls gives the same results)

So, the question, why the difference? I do not expect ls to run recursively without the -R flag

Anthony Kong

Posted 2010-10-14T23:08:34.187

Reputation: 3 117

Answers

6

This is because running ls with a folder name will list the contents of the folder(s) that match your argument.

Using * as a wildcard, any folders ending in py would have their contents listed, such as cherrypy, crappy, bumpy etc.

If multiple folders match the criteria, it will show you the folder names as well:

[~/ex]$touch bumpy/1
[~/ex]$touch sloppy/2
[~/ex]$touch cherrypy/3 cherrypy/4 cherrypy/5
[~/ex]$ls *py
bumpy:
1

cherrypy:
3  4  5

sloppy:
2
[~/ex]$

You did not have any folders or files directly in your current folder which ended in .py when you ran the first command, hence the output.

John T

Posted 2010-10-14T23:08:34.187

Reputation: 149 037