On Sunday 06 October 2002 18.43, Stephen H Carbin wrote:
First, I HAVE read the man page for find. I just can't understand how to turn its contents into working syntax (I'm sure its me that's the problem there.) Here is what I'm trying to do:
I have a directory called /test containing 2 files (passwd & motd ). My task is to use the find command to locate them (I know about the locate command, I need to use find), then I must display the last 2 lines of each. I really want to do this as 1 command. So far I have only managed to do it in 2 ... see below:
cat `find . -name passwd -print` | tail -2 more; cat `find . -name motd -print` | tail -2 | more
This produces the output that I want, but in 2 commands. A cursory look at the man page details Operators allowing multiple expressions with the -a & -and . Here are but a few of my futile attempts:
[steve@spot3 steve]$ find . -name passwd -and motd -print find: paths must precede expression Usage: find [path...] [expression] [steve@spot3 steve]$ find . -name passwd -and . -name motd -print
1) remove the second . to make find . -name passwd -and -name motd -print 2) observe that it's difficult for a file to be named "passwd" *and* "motd" at the same time, so find . -name passwd -or -name motd -print 3) observe that the -print only affects the expression preceding it, so find . \( -name passwd -or -name motd \) -print Note the spaces between the \( \) and the expression within 4) substitute the command you want to run for -print find . \( -name passwd -or -name motd \) -exec tail -f {} \; and you're done :) //Anders