This guide has been converted to a wiki:
https://help.ubuntu.com/community/find
Support is still available in this thread so feel free to ask any questions .
This guide has been converted to a wiki:
https://help.ubuntu.com/community/find
Support is still available in this thread so feel free to ask any questions .
Last edited by andrew.46; April 9th, 2012 at 10:20 AM.
You think that's air you're breathing now?
Yet another excellent guide. Good job, Andrew.
Nice guide... can you add searching within files? For example, there are a number of documents in a given directory. You want to find a keyword within them.
You think that's air you're breathing now?
Hi graysky,
There is an immense amount of material omitted in this guide, in part because this is intended to be an introduction only. But definitely I shall consider adding something like this in the near future. A 'real world' example of the usage of grep that you mentioned could be in my case finding all of the html files that mention 'slrn' in my offline website:
Fantastic program!!Code:$ find $HOME/html/andrews-corner -exec grep -q 'slrn' '{}' \; -print /home/andrew/html/andrews-corner/leafnode.html /home/andrew/html/andrews-corner/index.html /home/andrew/html/andrews-corner/slrn.html /home/andrew/html/andrews-corner/custom_os.patch /home/andrew/html/andrews-corner/mutt.html
Andrew
You think that's air you're breathing now?
Very cool.
How can I add an alias to my ~/.bashrc that will allow me to do this on the shell just by typing the alias and word or phrase?
For example, the alias might be called lookfor and what comes after that could be what you wanna search for inside the files in the current directory.
Example:
That would then do this:Code:$ lookfor lsrn
How can I do that?Code:find ./ -exec grep -q 'slrn' '{}' \; -print
Also, how would you handle a group of words?
Hi graysky,
An interesting question, and one that I had to do a little research on before I could answer properly . An actual alias would not do as bash aliases are not really meant to contain variables. What you ask for can be set as a bash function instead:
This would search the working directory and subdirectories with the syntax:Code:lookfor() { find . -exec grep -q "$1" '{}' \; -print }
which is what you specified. However a better idea would be to use two variables, the first being the path to search and the second being the search term:Code:lookfor search_term
and the syntax would then be:Code:lookfor() { find "$1" -exec grep -q "$2" '{}' \; -print }
Place this in ~/.bashrc and have a play with it. Mind you this starts moving towards a shell script which would of course be much more flexible.Code:lookfor path search_term
I am not entirely sure what you mean there, although I sense that your needs are slipping further away from 'find' and leaning more towards grep . In fact perhaps a simpler search with 'find' piped to grep would be better. Can you provide a specific example of what you need?Also, how would you handle a group of words?
All the best,
Andrew
You think that's air you're breathing now?
Superb guide, its really very helpful for me, Thanks andrew for sharing with us.
Thank you for a clear and concise intro guide. I have been weening myself off of gui now that I built a home server and appreciate this type of reference material.
Bookmarks