Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'zsh does all this!' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
zsh does all this!
Authored by: gidds on Feb 05, '03 11:56:39AM
I hope no-one minds me going on about it, but if you use the zsh shell instead of more primitive ones like bash, then the filename completion is so powerful you never need to use find.

For instance, the example above to set ownership of all a user's files, which using find looks like:

    find / -user foo -exec chown bar {} ;
can be written in zsh as
    chmod bar /**/*(u[foo])
Not only is this shorter and easier to write (once you're familiar with the idiom), but it's likely to run much faster as it only launches the chmod utility once, rather than repeatedly for each file.

To briefly explain that cryptic-looking search string: I'm sure you're all familiar with using * in a shell to give a list of all files in a directory.  Well, in zsh you can list files recursively: **/* lists all files in all subdirectories.  So /**/* lists all files starting at the root directory.  The bracketed expression restricts the files returned; in this case, it restricts them to the user `foo'. To restrict them to the current user, you'd simply use (U).

The syntax is extremely powerful: it's easy to restrict files based on filename, time of creation/last modification/access, permissions, size, type, links, with exclusions, ordering, in fact everything find can do and more.  And because it's not in a separate command, you have all the power of the shell in how you use the results.

I'm amazed more people don't use zsh; it's extremely powerful in many other ways too. Not only is it supplied with Mac OS X, but it's open source and available on many other platforms, and is backwardly-compatible with ksh for those who know that. man zsh for more details. You can change your default shell with the NetInfo Manager. (BTW, I have no connection other than as a happy user!)

[ Reply to This | # ]

zsh does all this!
Authored by: Az on Feb 05, '03 08:34:37PM
Hey Gidds

zsh?

Now that's a tip!

Thanks. I think I'll have a look into it - both for my FreeBSD box and my first Mac (12" P-book) when it arrives. Looks great - and simple!

Cheers!

[ Reply to This | # ]