Find the answer to your Linux question:
Results 1 to 2 of 2
I am just getting started with Linux (SUSE) and have what seems like a strange result. When applying a wildcard back in the ancient days when I did some Unix ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Location
    STL, USA
    Posts
    8

    Question Unexpected ls wildcard results? Am I crazy?


    I am just getting started with Linux (SUSE) and have what seems like a strange result. When applying a wildcard back in the ancient days when I did some Unix (or even DOS) I'm sure that a wildcarded directory request only produced a _subset_ of what was in the specified directory. Right? Am I crazy? Why is it that the results I get for ls a* doesn't list the items in the current directory that begin with 'a' but also lists the CONTENTS of those directories? Is this normal or do I have some goofy recursive user option messing with me? Thanks!

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    So the way that wildcard expansion works, the shell expands the wildcard, and passes the results to the program. The default behaviour of ls when given a directory on the commandline, is to expand that directory.

    This is the "ls" output of my test directory:
    Code:
    alex@niamh:~/test$ ls
    bash  c  c++  java  ruby
    And this is the "ls" output with a wildcard:
    Code:
    alex@niamh:~/test$ ls c*
    c:
    a.out        ckpt_file  map_file  popen_bash.c   read_to_noread_mem.c  type_sizes.c
    bitfields.c  file       ncurses   read_efault.c  shmem.c               userid.c
    
    c++:
    a.out  count.cpp
    If I do not want ls to expand directories, I can use the -d option:
    Code:
    alex@niamh:~/test$ ls -d c*
    c  c++

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •