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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago
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; 1 Week Ago at 12:25 PM.. Reason: Removed gratuitous additional formatting that was pasted in.
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 14 September 2017, 1:57 PM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,456
Thanks: 126
Thanked 192 Times in 173 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 1 Week Ago
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; 1 Week Ago at 12:29 PM.. Reason: RudiC added CODE tags. rbatte1 removed gratuitous pasted-in formatting
    #4  
Old Unix and Linux 1 Week Ago
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 15 September 2017, 11:35 AM EDT
Location: Lancashire, UK
Posts: 3,256
Thanks: 1,389
Thanked 630 Times in 569 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 1 Week Ago
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 20 September 2017, 1:41 PM EDT
Location: Simplicity
Posts: 3,744
Thanks: 306
Thanked 1,257 Times in 1,136 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; 6 Days Ago at 10:08 AM.. Reason: Changed non-ascii “– to "- thanks RudiC
Sponsored Links
    #6  
Old Unix and Linux 6 Days Ago
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 6 Days Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 20 September 2017, 1:16 PM EDT
Location: Aachen, Germany
Posts: 11,352
Thanks: 297
Thanked 3,521 Times in 3,240 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
Reply

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 02:08 PM.