Shell - noding files from the current day


Im using this command to get some info from the files below:

> find /var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents* -type f -mtime -7 -print0 | xargs -0 grep SmartPrM | wc -l

Is there a way for it not to take the files that has the timestamp of the current day?

For example, lets say I have files like this:


Using the command above Im reading the files from the day 09/24 to the 09/17  (considering today as 09/24)

So, Is there a way for it to read the files from 09/23 to 09/17 ? NOT reading the files from 09/24 ?

Joao Telles
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add the -a ! -mtime 0.  Also corrected your inefficient file globbing and unnecessary use of wc

find /var/opt/smarttreee/dpa/log/event/output -name "TrafficErrorEvents*" -type f -mtime -7 -a ! -mtime 0 -print0 | xargs -0 grep -c SmartPrM 

Open in new window

joaotellesAuthor Commented:

I ran the command but I have some questions:

> find /var/opt/smarttreee/dpa/log/event/output -name "TrafficErrorEvents*" -type f -mtime -7 -a ! -mtime 0 -print0 | xargs -0 grep -c SmartPrM

The output was like this:


But I need the total of all files, not individually like this... can it be done?

Also I noticed that it analized: 183 files.

find /var/opt/smarttrust/dpa/log/event/output -name "TrafficErrorEvents*" -type f -mtime -7 -a ! -mtime 0 -print0 | xargs -0 grep -c SmartProv_TEXTSM | wc -l

But I have 226 files from 09/24 to 09/18 (seven days before today)... Not sure it didnt analized all files...

Maybe your command works getting the last 24hrs instead of picking the files per timestamp?

If it works using the clock (24hrs before now).. If run it now, some files of yesterday will not be analized and this is not the goal here..

Depending on your OS, you can use the -daystart flag:

              Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago.

So combing that and adding the total of all files, use:

find /var/opt/smarttreee/dpa/log/event/output -name "TrafficErrorEvents*" -type f -mtime -7 -a ! -mtime 0 | xargs cat | grep -c SmartPrm

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
if daystart is unavailable, you can always touch a file at midnight and use -newer flag (negated)

if you are using daily log rotations and a system that supports ctime, ctimes will work out-of the box
joaotellesAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.