ls - wildcards and global use

ropers

Registered
Hiya,

I want to list all files missing a certain pattern and/or filename pattern on the entire drive.

In DOS I would type (for instance):

dir \t*.doc /s /a

which should find all doc files whose filename starts with `t'.

How to I do that in a unix shell. Can it be done w/ ls at all? I don't seem to succeed, and yes, I've read the man pages, but either I don't understand them correctly or it's not doing what it's supposed to do. For instance: I've tried: ls -AFR com.* from root dir, and it doesn't find stuff in subfolders.
(Ok, you got me, I'm a unix newbie.)

uses:
Mac OS X
tcsh

I'm looking for a solution that would work with most shells, sh, csh, tcsh, bash, you name it.


Also, the man pages frequently mention I can press tab or esc x 2 for choice/filename/dirname completion, but that doesn't seem to work on my (default Mac OS X terminal) tcsh either?

cheers,

the rop
 
Originally posted by gumse
find / -name "t*.doc"

Hm, alroight. Cool. But what's the story w/ ls -R? I don't really get it why it doesn't seem to recurse subdirs as that is what it says it does?
 
Learn find. It's syntax is somewhat arcane, but it's a very powerful tool and you won't regret spending the time to learn it. There are few things you can't do by piping the output of find into xargs. :)
 
The biggest thing about using wildcards with programs is to understand how those wildcards are expanded. If I'm in a directory with the files file1, file2, file3 and I do ls f* what actually happens is the shell I'm using will expand that f* PRIOR to passing arguments to ls. If you try to get fancy, like ls -R f* thinking it will find all files, recursively, starting with f, you'll be surprised since the shell is expanding the wildcard. Hence the actual ls command becomes ls -R file1 file2 file3 which lists file1, file2, and file3 recursively (which is kinda pointless, since they're files, but would work as expected if they are directories).

As has been mentioned, if you want to find files, as opposed to just listing information about them, use the find command; or locate works as well (and is faster as it uses a prebuilt file database, but also because of this, can report stale information).

Also, since this is Unix after all, you can get fancy: ls -R / | grep "t.*doc" will list everything recursively, then uses grep to weed out only files which start with t and end with doc (note, that string is a regular expression, so t.*doc is right, as opposed to t*doc; if you want specifically files ending in .doc, you need t.*\.doc). man re_format if you're curious about the powerful, yet ugly, regular expressions...
 
Originally posted by testuser
blb,

Your knowledge of unix shells and regex are impressive indeed. Could you recommend any books that would bring the rest of us up to your level? (Or at least start us on the way?)

Yikes, that's a big question...what I can say is I do have the advantage of having used various Unixen over the past decade (and of course, Mac, Windows, DOS, VMS, etc...).

There is a book for those who want to know more about regex than you probably ever need, Mastering Regular Expressions .

For the more generic Unix stuff, most of my knowledge comes from just playing around (especially when I got hold of the first Unix I touched, Minix , on a 286).

I believe a number of people have mentioned various books at the user level, the ones I've used at the admin level include Unix System Administration Handbook and of course quite a few O'Reilly books
 
Back
Top