#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    22
    Rep Power
    0

    Exec command with grep output


    Hello,

    I have a requirement to find the files having its name as ack_reply. However, there are many other files in the same directory as these resides. Now I have to remove these files from the folder and retain others after 7 days. So I tried to write the below script with grep command.

    find $directory -type f -mtime +7 | grep ack_reply

    Please let me know how can I pass this output to -exec command.

    If I am not using grep command my script would be as

    find $directory -type f -mtime +7 -exec remove.sh {}\\;;

    How can I use -exec with grep and find. Please let me know
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    Rather than using 'grep', you can use the -name option to 'find', i.e.:
    Code:
    find $directory -type f -mtime +7 -name ack_reply -exec remove.sh {} \;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    22
    Rep Power
    0
    But we can use -name when the file name is with ack_reply. My requirement is to identify all the files that have filenames as ack_reply some where in between. I mean the ack_reply is part of a file name
  6. #4
  7. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    In that case:
    Code:
    find $directory -type f -mtime +7 -name "*ack_reply*" -exec remove.sh {} \;
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    22
    Rep Power
    0
    Thanks..this helped me a lot

IMN logo majestic logo threadwatch logo seochat tools logo