Find the answer to your Linux question:
Results 1 to 6 of 6
Hi Does anyone know of any file search commands in unix? thanks q :o Weel...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2003
    Posts
    8

    search commands


    Hi

    Does anyone know of any file search commands in unix?

    thanks

    q :o Weel

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The most common one is "find". If you have the slocate package installed you can also use "locate".

  3. #3
    Just Joined!
    Join Date
    May 2003
    Posts
    8

    find

    Does that do a search or just work in the same directory that you do it in?.

    I presume its find [filename]

    Thanks

  4. #4
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    The 'find' is the best. The format I usually use (although this reads through the hard drive at an incredible rate) is as follows:
    Code:
    find <path> -name "<regular expression> " -print
    So if I wanted to find all the files ending in .mpg in my home directory, I'd use this following command:
    Code:
    find . -name "*.mpg" -print
    1st field is the command find, 2nd field is the path (dot represents current directory), 3rd field is the -name option followed by it's argument inside double quotes. *.mpg means find every file that ends in .mpg. The last field, -print, is another option in find that prints the path of all the results. You can always run 'man find' to find more information but as always, I find man pages are harder to read if you are a novice.
    NOTE: find is a recursive command meaning it'll search subdirectories from the path you specify.
    The best things in life are free.

  5. #5
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    You can always check the manpage for find for more options. It is an extremely powerful command. For example, I often use this:
    Code:
    find -name '*.c' -exec grep -H <something> &#123;&#125; \;
    That searches (from the current directory) for C files and finds which of them contains a certain regexp.

  6. #6
    Linux User
    Join Date
    May 2003
    Location
    CA
    Posts
    370
    I use somethg similar

    # find <pathname> -exec grep "pattern" {} \; -print

    Thnks,
    Nik

Posting Permissions

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