Find files in Linux

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Theadmin77
    New Member
    • Nov 2006
    • 19

    Find files in Linux

    I m kind of stuck ...i need to find files with a specific criteria but i can not make it work ....

    These are the ones :

    1.How do you Find files under /root that contain the whole words (i.e., not part of another word) 'foo', 'bar', 'baz', 'cat', 'cut', 'cot.' using a single command ?

    I tried :find /root -name 'foo.*' -name 'baz.*'-name 'cat.*'-name 'cut.*'-name 'cot.*'
    but seems that is not right

    2.Find files under /var that contain the character list 'xxx' or 'xxxx' or 'xxxxx'. Using \{\} and adding two lines of context before AND after each keyword found. ..

    my answer: find /var -name 'xxx' ,'xxxx, 'xxxxx'

    At this point i am lost ....

    Any help will be very much appreciated
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by Theadmin77
    I m kind of stuck ...i need to find files with a specific criteria but i can not make it work ....

    These are the ones :

    1.How do you Find files under /root that contain the whole words (i.e., not part of another word) 'foo', 'bar', 'baz', 'cat', 'cut', 'cot.' using a single command ?

    I tried :find /root -name 'foo.*' -name 'baz.*'-name 'cat.*'-name 'cut.*'-name 'cot.*'
    but seems that is not right

    2.Find files under /var that contain the character list 'xxx' or 'xxxx' or 'xxxxx'. Using \{\} and adding two lines of context before AND after each keyword found. ..

    my answer: find /var -name 'xxx' ,'xxxx, 'xxxxx'

    At this point i am lost ....

    Any help will be very much appreciated
    For number 1, do you mean that have filenames containing those words, or the files themselves containing those words?
    The tools you want in the latter case are grep and sed, not find.
    Actually, I think both questions are looking for answers involving sed.

    A little more on sed.
    Required reading for sed (i.e. Regular Expressions).

    Comment

    • Theadmin77
      New Member
      • Nov 2006
      • 19

      #3
      No , i s not grep because we are looking for file names no strings within a file .
      I know FIND must be used but i dont remember the correct parameters ..

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by Theadmin77
        No , i s not grep because we are looking for file names no strings within a file .
        I know FIND must be used but i dont remember the correct parameters ..
        In the future, you can use the command line utility man to find syntax for linux commands:

        Code:
        % man find
        Here is a web version of the man page.

        Comment

        • kvbreddy
          New Member
          • Feb 2007
          • 23

          #5
          find /root -name 'foo' -print is the command to find files

          Comment

          Working...