3

From Unix Power Tools 3rd Edition page 175:

Article 9.27 shows a way to match directories in the middle of a path. Here's a simpler "find file" alias that can come in very handy:

alias ff "find . -name '*\!{*}*' -ls"

Give it a file or directory name; the alias will give a long listing of any file or directory names that contain the argument.

(This is also available online.)

I don't get the argument to the -name operator at all. Is this a typo? Is it only for specific versions of find? What are the backslash, bang and curly braces doing?

4
  • Which shell are they using? That doesn't look like bash. Otherwise I'd have guessed !{*} to be some sort of history interaction.
    – muru
    Dec 17, 2015 at 8:53
  • Most of the book (the parts that I've read so far) are either not shell specific or are very good about specifying what is non-portable or zsh specific, etc. This one article/section appears to be an oddity. It's definitely not bash; they don't even have an = sign to set the alias. The rest of the book seems quite excellent but this one line is "WTF?!"
    – Wildcard
    Dec 17, 2015 at 8:56
  • 2
    It looks like (t)csh (! is alias argument expansion). Dec 17, 2015 at 9:03
  • 1
    would you accept or what?
    – mikeserv
    Dec 17, 2015 at 10:39

1 Answer 1

7

That's a csh alias; the argument given to -name is interpreted by the shell, not by find. If I understand it correctly, \!{*} is replaced by the arguments given to ff (although that would usually just be \!*). It is odd indeed that the book doesn't specify the shell...

Basically with the alias defined, typing

ff test

runs

find . -name '*test*' -ls

(and it doesn't handle multiple arguments gracefully).

In the second edition of the book, the text defines the alias in the same way as given in the question, and points to csh_init and sh_init on the accompanying CD. (It's section 17.04.) Intriguingly, csh_init on the CD doesn't define the alias, but sh_init defines an equivalent ff function:

ff() { find . -name "*$1*" -ls; }
2
  • That's it exactly, and now it makes sense. As you say it is odd indeed that they didn't specify the shell for that one. I'll have to stay on the lookout. But in fairness to the authors, I'd say the need for a little watchfulness is still worth it; the book is excellent and should be a staple for sysadmins.
    – Wildcard
    Dec 17, 2015 at 9:19
  • 1
    The book is indeed excellent, I have the second edition and learnt a lot from it back in the day! Dec 17, 2015 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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