<html><body>Hi again Dominic<br /><br />On 20 September 2011 17:06, Dominic Humphries <linux@oneandoneis2.org> wrote:<br />>> What I don't understand about this command is that it just returns an<br />>> alphabetised list of the root folders and files inside /home/fay<br />><br />> This is because the command enclosed in backticks returns nothing, so<br />> the above is basically the same as 'ls -l' which will default to your<br />> current directory.<br /><br />Doh!<br /><br />> It looks like<br />> $ find . -name '*listit*' | grep -v 'Downloads' | grep -v '/home/fay/listit/'<br />><br />> would be the 'find' command you want, given the above scenario.<br /><br />I tested this one out but I couldn't get it to work.<br />The output from the find command doesn't include the /home/fay part.<br />So it's been reduced from an absolute path to a relative path.<br />Each result begins with ./ and that's what grep receives.<br /><br />$ find . -name '*listit*' | grep -v 'Downloads'<br />produces:<br />./Documents/how_to_choose_what_to_buy/listit<br />./Documents/how_to_choose_what_to_buy/listit/testlistit.html<br />./listit<br />./listit/january_listit.txt<br />and I only want the second result from that list.<br /><br />Using the -type argument to restrict output to regular files as <br />suggested by David B (18:58 post):<br /><br />$ find . -type f -name '*listit*' | grep -v 'Downloads'<br />produces:<br />./Documents/how_to_choose_what_to_buy/listit/testlistit.html<br />./listit/january_listit.txt<br />gets me closer.<br /><br />I still need help working out how to exclude results from the one <br />/listit/ directory while still including results from the other <br />/listit/ directory. In practice, there could be other /listit/ <br />directories dotted around, but only the one /home/fay/listit/.<br /><br />From man find:<br /><br />-name pattern<br />Base of file name (the path with the leading directories<br />removed) matches shell pattern pattern. The metacharacters<br />(‘*', ‘?', and ‘[]') match a ‘.' at the start of the base name<br />(this is a change in findutils-4.2.2; see section STANDARDS CON‐<br />FORMANCE below). To ignore a directory and the files under it,<br />use -prune; see an example in the description of -path.<br /><br />-path pattern<br />File name matches shell pattern pattern. The metacharacters do<br />not treat ‘/' or ‘.' specially; so, for example,<br /> find . -path "./sr*sc"<br />will print an entry for a directory called ‘./src/misc' (if one<br />exists). To ignore a whole directory tree, use -prune rather<br />than checking every file in the tree. For example, to skip the<br />directory ‘src/emacs' and all files and directories under it,<br />and print the names of the other files found, do something like<br />this:<br /> find . -path ./src/emacs -prune -o -print<br />Note that the pattern match test applies to the whole file name,<br />starting from one of the start points named on the command line.<br />It would only make sense to use an absolute path name here if<br />the relevant start point is also an absolute path.<br /><br />From these entries , I can't tell where to place the path I want to <br />exclude. This command returns nothing:<br /><br />$ find . -type f -name '*listit*' -path /home/fay/listit -prune | grep -v 'Downloads'<br /><br /><br />
                Best Regards,<br />Fay<br />East Grinstead Linux User Group<br />www.eglug.org.uk<br /><br /></body></html>