Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Grep Script

Shell Programming and Scripting


Tags
scripting

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-13-2017   -   Original Discussion by Con592
Con592's Unix or Linux Image
Con592 Con592 is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 20 September 2017, 6:05 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Grep Script

Hi,
New to scripting and looking for some help.
I am trying to write a script that will search a specified directory for any new or modified files within the last 7 days and display the results. This will be ran daily and emailed?
Thanks

Last edited by rbatte1; 09-13-2017 at 12:25 PM.. Reason: Removed gratuitous additional formatting that was pasted in.
Sponsored Links
    #2  
Old Unix and Linux 09-13-2017   -   Original Discussion by Con592
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 19 April 2018, 10:18 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,480
Thanks: 142
Thanked 209 Times in 184 Posts
What have you tried?

What have you tried?
What do you believe would solve this?

We are not a coding service, and some requests like this have a "school work" feel to them.

Please provide information on what you have attempted.
Sponsored Links
    #3  
Old Unix and Linux 09-13-2017   -   Original Discussion by Con592
Con592's Unix or Linux Image
Con592 Con592 is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 20 September 2017, 6:05 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts


Code:
Find (directory) –name “*.file extention” –mmin -1440 – print

Is basically giving me what I am after just wanting the files to display in the results though not full paths?



Moderator's Comments:
Grep Script Please use CODE tags as required by forum rules!

Last edited by rbatte1; 09-13-2017 at 12:29 PM.. Reason: RudiC added CODE tags. rbatte1 removed gratuitous pasted-in formatting
    #4  
Old Unix and Linux 09-13-2017   -   Original Discussion by Con592
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 19 April 2018, 8:53 AM EDT
Location: Lancashire, UK
Posts: 3,508
Thanks: 1,544
Thanked 689 Times in 619 Posts
Welcome Con592,

I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.



Kind regards,
Robin
Sponsored Links
    #5  
Old Unix and Linux 09-13-2017   -   Original Discussion by Con592
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 20 April 2018, 2:00 AM EDT
Location: Simplicity
Posts: 4,032
Thanks: 346
Thanked 1,356 Times in 1,222 Posts
You can cd to the directory and use a relative path


Code:
find . -type f -name "*.ext" -mmin -1440 -print

Or you filter the output


Code:
directory="directory"
find "$directory" -type f -name "*.ext" -mmin -1440 -print | sed "s#^$directory##'

For long times like 7 days you better take -mtime -7 not -mmin -10080.

Last edited by MadeInGermany; 09-14-2017 at 10:08 AM.. Reason: Changed non-ascii “– to "- thanks RudiC
Sponsored Links
    #6  
Old Unix and Linux 09-14-2017   -   Original Discussion by Con592
Con592's Unix or Linux Image
Con592 Con592 is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 20 September 2017, 6:05 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
Thanks for the info.


How can I get more info from the find output, for example modified date etc in the output?
Sponsored Links
    #7  
Old Unix and Linux 09-14-2017   -   Original Discussion by Con592
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 20 April 2018, 3:17 AM EDT
Location: Aachen, Germany
Posts: 12,494
Thanks: 401
Thanked 3,872 Times in 3,560 Posts
Does your find version offer the -ls action? And, I'm pretty sure no find version will work with the non-ascii – “ ” characters...
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with script - GREP mirkocosta Shell Programming and Scripting 7 08-03-2015 07:47 AM
script use min resource ( grep grep) pooyair Shell Programming and Scripting 8 03-07-2011 10:43 AM
How to grep sql error in shell script and exit the script? allinshell99 Shell Programming and Scripting 2 05-27-2010 09:06 PM
trying to grep the first few lines of a continuos script, and exit the script anyidea k00061804 UNIX for Dummies Questions & Answers 5 07-22-2009 12:15 PM
grep script drchris UNIX for Dummies Questions & Answers 4 05-17-2007 09:32 AM



All times are GMT -4. The time now is 03:18 AM.