Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.mac.system > #55010
| From | nospam <nospam@nospam.invalid> |
|---|---|
| Newsgroups | comp.sys.mac.system |
| Subject | Re: Question about wildcards in Unix |
| Date | 2014-01-19 19:02 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <190120141902517091%nospam@nospam.invalid> (permalink) |
| References | <52dc4f96$0$2686$c3e8da3$66d3cc2f@news.astraweb.com> <52dc55d7$0$39541$c3e8da3$50a2033e@news.astraweb.com> <52dc5ccf$0$58768$c3e8da3$12bcf670@news.astraweb.com> <1lfruh8.1ni6lfs1qgbzg2N%dempson@actrix.gen.nz> |
In article <1lfruh8.1ni6lfs1qgbzg2N%dempson@actrix.gen.nz>, David Empson <dempson@actrix.gen.nz> wrote: > JF Mezei <jfmezei.spamnot@vaxination.ca> wrote: > > > On 14-01-19 17:46, Joanna Shuttleworth wrote: > > > > > >> ls -R *.c only lists .c files in the current directory > > >> ls -R */*.c will list .c files in any subdirectory > > > > > no, but the first command would recursively list the entire contents > > > of any directory with a name ending in '.c'. > > > > That is the problem. It doesn't do that. It only lists .c files present > > in the current directory and does not go into subdirectories to look for > > other .c files. > > Read what nospam said again. it wasn't me. i haven't been a part of this thread (until now). > If the current directory contains a subdirectory which has a name ending > in ".c", then "ls -R *.c" will recursiely list the entire contents of > that subdirectory (and any other similarly named subdirectories in the > current directory). > > It will also list any files in the current directory which have names > ending in .c. > > This is because the "*.c" wildcard in "ls -R *.c" is expanded by the > shell, replacing it with the name of all files and subdirectories in the > current directory, before the whole command is passed to ls. > > For example, if the current directory contained files a.c and b.c, and a > subdirectory called more.c, then "ls -R *.c" would be expanded by the > shell to "ls -R a.c b.c more.c". The ls command would list the files a.c > and b.c, then the entire contents (recursively) of the more.c > subdirectory (all files in that subdirectory would be listed, not just > filenames ending in ".c"). > > As Siri Cruz said, the "find" tool is a better way to do what you want: > > find . -name '*.c' -print > > This will list all files in the current directory and recursively in all > subdirectories which have a name matching the pattern '*.c'. > > In this case, the '*.c' is not expanded by the shell because of the > single quotes. It gets passed to the find command, which uses it as a > pattern to match. > > > The second command you used (ls -R */*.c) is also not doing quite what > you think it is doing. > > In this case, the shell will expand */*.c to all files with names ending > in ".c" which are in all first level subdirectories of the current > directory, then pass them to ls, which will list them. It won't list any > ".c" files in the current directory, nor in any second level (or deeper) > subdirectories. > > The -R option only comes into play if any of the files in the first > level subdirectories happen to be a subdirectory with a name ending in > ".c", in which case ls will also list the entire content of that > subdirectory recursively.
Back to comp.sys.mac.system | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about wildcards in Unix JF Mezei <jfmezei.spamnot@vaxination.ca> - 2014-01-19 17:19 -0500
Re: Question about wildcards in Unix Siri Cruz <chine.bleu@yahoo.com> - 2014-01-19 14:42 -0800
Re: Question about wildcards in Unix Joanna Shuttleworth <js@example.com> - 2014-01-19 22:46 +0000
Re: Question about wildcards in Unix JF Mezei <jfmezei.spamnot@vaxination.ca> - 2014-01-19 18:16 -0500
Re: Question about wildcards in Unix dempson@actrix.gen.nz (David Empson) - 2014-01-20 12:43 +1300
Re: Question about wildcards in Unix nospam <nospam@nospam.invalid> - 2014-01-19 19:02 -0500
Re: Question about wildcards in Unix dempson@actrix.gen.nz (David Empson) - 2014-01-20 17:41 +1300
Re: Question about wildcards in Unix JF Mezei <jfmezei.spamnot@vaxination.ca> - 2014-01-19 19:55 -0500
Re: Question about wildcards in Unix Jolly Roger <jollyroger@pobox.com> - 2014-01-20 03:00 +0000
Re: Question about wildcards in Unix mcarels@xs4all.nl (Maarten Carels) - 2014-01-20 10:05 +0100
Re: Question about wildcards in Unix Tim Streater <timstreater@greenbee.net> - 2014-01-20 09:49 +0000
Re: Question about wildcards in Unix Doug Anderson <ethelthelogremovethis@gmail.com> - 2014-01-20 12:57 -0800
Re: Question about wildcards in Unix JF Mezei <jfmezei.spamnot@vaxination.ca> - 2014-01-20 16:15 -0500
Re: Question about wildcards in Unix Doug Anderson <ethelthelogremovethis@gmail.com> - 2014-01-20 14:10 -0800
Re: Question about wildcards in Unix Tim Streater <timstreater@greenbee.net> - 2014-01-20 23:06 +0000
Re: Question about wildcards in Unix Doug Anderson <ethelthelogremovethis@gmail.com> - 2014-01-20 16:39 -0800
Re: Question about wildcards in Unix nospam <nospam@nospam.invalid> - 2014-01-20 18:44 -0500
Re: Question about wildcards in Unix Doug Anderson <ethelthelogremovethis@gmail.com> - 2014-01-20 16:42 -0800
Re: Question about wildcards in Unix Tim Streater <timstreater@greenbee.net> - 2014-01-21 10:23 +0000
Re: Question about wildcards in Unix Jolly Roger <jollyroger@pobox.com> - 2014-01-20 18:43 +0000
Re: Question about wildcards in Unix Doug Anderson <ethelthelogremovethis@gmail.com> - 2014-01-20 12:55 -0800
csiph-web