Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running Ubuntu as VM in VMWare Fusion on MacPro:

ayakovlev@ubuntu:~$ uname -a
Linux ubuntu #1 SMP Thu Mar 6 15:31:54 EST 2014 x86_64 x86_64 x86_64 GNU/Linux

The command below outputs result which I expect:

ayakovlev@ubuntu:~$ ls /usr/include/*5*

When I replace 5 by 6 I get very strange results:

ayakovlev@ubuntu:~$ ls /usr/include/*6*
a.out.h  asm  bits  c++  fpu_control.h  gnu  ieee754.h  sys  zconf.h

What might be a reason for that?

share|improve this question
up vote 2 down vote accepted

As @Sparhawk explained, what is happening is that you are listing the content of the directories. This will not depend on the *nix you are using, as far as I know, this is the default behavior of GNU ls. Non-GNU implementations may be different but I doubt it.

When you run this command:

ls /usr/include/*6*

The glob (*6*) is expanded by your shell (bash for example) before calling ls. So, given the following directory structure:

├── dir1
│   ├── file1
│   └── file2
└── dir2
    ├── file1
    └── file2

ls d* will be expanded to ls dir1 dir2, and give the results you expect:

file1  file2

file1  file2

This is how ls deals with multiple target directories by default, it lists each directory found and then the contents of that directory. However, if you run it on a single directory, the name is not printed:

$ ls d*1
file1  file2

So, since there is only one match for the glob *6* in /usr/include and that match is a directory, you are running ls with a single directory as input and, therefore, it is listing the contents of the directory without including the directory name.

share|improve this answer

The wildcards in ls /usr/include/*6* expand to whatever matches. In the first case, it matched specific regular files. However, if it matches directories such as /usr/include/x86_64-linux-gnu, it'll print out the contents of those directories instead (i.e. it would have expanded to ls /usr/include/x86_64-linux-gnu).

You can verify that the wildcard would have expanded to a directory with ls /usr/include | grep 6.

share|improve this answer
To list directories entries instead of its contents you can use -d: ls -d /usr/include/*6*. – Eric Carvalho Mar 24 '14 at 1:32
In all other Unixes I worked the ls used to show a directory before list of files from this directory. Including the Mac OS X, where I can see a bunch of directories, containing the digit 6, followed by files from these directories. – HEKTO Mar 24 '14 at 2:06
@AlekseyYakovlev I see the same thing in Ubuntu, but only if there are multiple matches for the wildcard. If the wildcard only matches one item, and it is a directory, it won't list the directory name before listing the contents. – Sparhawk Mar 24 '14 at 2:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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