• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Unix Find: Question for the experts"

Collapse

  • OwlHoot
    replied
    Originally posted by Cowboy Bob
    cd <root directory to search from>
    grep "whattofind" `find .`

    Note that is the apostrophe below the escape key on most keyboards.
    You don't have to cd.

    find <directory_to_search_from> -print -name <wildcard> -exec grep <whattofind> {} \;

    where <wildcard> is a pattern of the files you want to search, e.g. *.c (or for that matter fred.c if you only want to check files of that name).

    On some versions of unix the file paths won't be printed unless you use the -print argument, although I think this is usually redundant these days.

    (Needless to say none of the '<' or '>' symbols are redirects in the above.)

    edit: On most unices these days the grep command has a -r option (for 'recursive', i.e. a treewalk a-la find)
    Last edited by OwlHoot; 21 July 2007, 05:05.

    Leave a comment:


  • sappatz
    replied
    /home/MilanB

    /home/MilanB

    is a corrupted filesystem. it needs to be rebuilt from scratch and socially reformatted

    Leave a comment:


  • OrangeHopper
    replied
    Similar to suggestion above.

    find . | xargs grep <string>

    Leave a comment:


  • milanbenes
    replied
    Pondlife,

    less of it.

    I'm doing a hardware migration

    took an offline backup of the existing

    created filesystems and users on the new host

    restored the backup to the new host

    changing the hostname EVERYWHERE to the new hostname and trying to get the system to startup

    Everything's workin' fine apart from one component

    Milan.

    Leave a comment:


  • Pondlife
    replied
    Stop

    Milan,

    You really think you should be doing this? Sounds a little like we're pushing out boundaries a bit. .net is far easier in a windows environment.

    Remember, if you don't do it they can always get some permie to take the risk.

    Leave a comment:


  • milanbenes
    replied
    good work Chubba, points awarded

    from what I can see there are several schools of thought on this finding a string in a file on unix

    good work lads

    Milan.

    Leave a comment:


  • chubba
    replied
    I missed the points for being too slow but I usually use:

    Code:
    find /home/chubba/ -type f -exec grep -H 'chubba' {} \;
    To find the word 'chubba' in my home folder...

    Leave a comment:


  • milanbenes
    replied
    thanks again,

    top reward points go to SysMan's link

    excellent

    Milan.

    Leave a comment:


  • Euro-commuter
    replied
    Originally posted by milanbenes
    Team,

    if I am in for example my filesystem on Unix
    eg:

    /home/MilanB

    is it possible to do a find, but to search for a string in all of the files in the file system ?


    Like:

    find <this string> in any files in this filesystem

    Thanks,

    Milan.
    not tested but off the top of my head

    ls -R | xargs grep <string>

    -R recursively lists subdirs; the superbly useful xargs splits input into sets of strings, not too many for the specified command to handle (otherwise "ls -R" may well return too many results for grep to swallow).

    Edit: sorry, didn't read carefully. Do you specifically want to do a unix "find"?
    What results do you want? List of all found strings, or just a list of files with the string? That would be grep -l (that's a lower case letter ell).


    Note: interestingly, I described how to use grep with ls (or it could have been find) as a subsidiary tool; previous link described how to use find with grep as a subsidiary tool.

    So much for unix's "have only one way of doing something".

    Question: is it really true that one is subsidiary to the other, or are they coroutines?
    Last edited by Euro-commuter; 20 July 2007, 09:25.

    Leave a comment:


  • milanbenes
    replied
    Team,

    you're the best, the project wouldn't be the same without you.

    Thanks,

    Milan.

    Leave a comment:


  • Euro-commuter
    replied
    Originally posted by barely_pointless
    don't forget the -r and do it from / and it may take some time ......

    Leave a comment:


  • Sysman
    replied
    http://www.athabascau.ca/html/depts/...HOWTO/find.htm

    and see the bottom of the page.

    Leave a comment:


  • barely_pointless
    replied
    Originally posted by zeitghost
    I prefer rm * myself.

    don't forget the -r and do it from / and it may take some time ......

    Leave a comment:


  • Chugnut
    replied
    Can't remember the exact syntax but Google the grep command.

    Leave a comment:


  • barely_pointless
    replied
    use -->

    man grep

    to get all the various flavours and examples, or else buy "Unix in a Nutshell" , now there's a book that has saved my ar5e more than once.

    Leave a comment:

Working...
X