Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
sorry if this is in the wrong spot, but I want to search all the files in a directory for a piece of text...thanks for any help you guys can ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    6

    find test within files

    sorry if this is in the wrong spot, but I want to search all the files in a directory for a piece of text...thanks for any help you guys can give me

  2. #2
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,298
    try this

    Code:
    grep -R test ~
    Which will search (grep) your home directory (~) and all subdirectories (-R) for
    the text test
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    6
    I guess I forgot to say, but I'm using MINIX and -R is not an opinion within Minix, is there any other way to do this with -R?

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Josh803 View Post
    I guess I forgot to say, but I'm using MINIX and -R is not an opinion within Minix, is there any other way to do this with -R?
    If "find" is available, you can do it this way:

    Code:
    find . -exec  grep foo '{}' \;
    This will find all the files starting on the current dir (.) and then grep each of those files searching for the string "foo".

  5. #5
    Just Joined!
    Join Date
    Apr 2008
    Posts
    6
    thanks guys for all your help and it all most works, but now when I run that command it gives me the message "grep: couldn't open"...any suggestions?

  6. #6
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Josh803 View Post
    thanks guys for all your help and it all most works, but now when I run that command it gives me the message "grep: couldn't open"...any suggestions?
    Does that happen with all the files? Do you have read permissions ver these files? If affirmative, can you post the exact error messages?

    It should work as long as the find and grep tools are standard, I think. Though I don't have any experience with minix, to tell the truth.

    Also, are these regular files or are they any other kind of files? (symlinks, sockets, device nodes and the like).

  7. #7
    Linux User netstrider's Avatar
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    474
    I don't know if this works in Minix, but I believe it should. Check if grep is there..

    Code:
    which grep
    that way we can take the problem further if grep proves to be available, else check if grep is available for Minix.

    PS: Output should be something like this:
    Code:
    uholtz@atom:~$ which grep
    /bin/grep

  8. #8
    Just Joined!
    Join Date
    Apr 2008
    Posts
    6
    I do have read and write permission on all the files and "grep: couldn't open" is the exact message I get, and it displays it for every file in the directory. grep is also installed(/usr/bin/grep) and all the files are .h or .c files so I think I should be able to read from them

  9. #9
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Josh803 View Post
    I do have read and write permission on all the files and "grep: couldn't open" is the exact message I get, and it displays it for every file in the directory. grep is also installed(/usr/bin/grep) and all the files are .h or .c files so I think I should be able to read from them
    Does it do anything if you use another command? For example:

    Code:
    find . -exec  ls -l '{}' \;

  10. #10
    Just Joined!
    Join Date
    Apr 2008
    Posts
    6
    I don't know what it is, but that didn't work either. it just gave me a message "ls: (); No such file or directory"...I thought I could use the grep command and some how pip the find command with it but so far have been unsuccessful

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...