Solved

unix find command with timestamp

Posted on 2011-03-15
16
863 Views
Last Modified: 2012-05-11
I need to use find and count comand to list all files under  one level of sub directories with timestamp in last 45 mins from current time.

Main directory

/export

sub dir's

/export/zone1
/export/zone2
.
.
/export/zonen

file name
xyz*  with timestamp for last 15 mins.
0
Comment
Question by:pal2k
  • 10
  • 6
16 Comments
 

Author Comment

by:pal2k
ID: 35140334
correction 45 mins
0
 
LVL 8

Accepted Solution

by:
point_pleasant earned 500 total points
ID: 35140837
find /export/zone*/xyz* -mmin -45 | wc -l
0
 

Author Comment

by:pal2k
ID: 35141694
Thanks...Actually I will do cd to /export

From current directory I have bunch of sub-directories starting zone* and file names xyz*
But I need list files foronly  todays date with timestamp  within  last 45 mins

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 8

Expert Comment

by:point_pleasant
ID: 35141717
ok if you just need a list then leave off the |wc -l.  you could direct the output to a file with
find /export/zone*/xyz* -mmin -45 -print > file_name and then junk do wc -l file_name to get a count



Mike
0
 

Author Comment

by:pal2k
ID: 35142563
I got this error

find: bad option -mmin
find: [-H | -L] path-list predicate-list

0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35147081
What Unix platform are u running on?
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35147157
see if your find command supports

the -cmin -45 option
0
 
LVL 8

Assisted Solution

by:point_pleasant
point_pleasant earned 500 total points
ID: 35147496
If your Linux version does not support -mmin or -cmin you can try the following


#!/usr/bin/ksh
#----subtract 45 minutes (2700 seconds) from time
STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 2700);
printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm')

#----create an empty file with a timestamp of 45: minutes ago
touch -t $STAMP /tmp/flagfile

#----find older files
cd /export
find . -name zone*/xyz* -type f -newer /tmp/flagfile -print |\
while read FILE
do
  echo $FILE
done
0
 

Author Comment

by:pal2k
ID: 35210998
It is Slorais machine...

I dont see cmin , mmim or mtime working....

how do I check if the utility exist or any other find/list command to see files with last 45 mins modified or created.
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35214548
see my previous comment


ID:35147496
0
 

Author Comment

by:pal2k
ID: 35215365
I appreciate it. But the problem is I cant use a script. I have to do it from command line only using Unix command.
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35215531
the only way i can think of to do it from command line is a two step ptocess


touch -t YYYYMMDDHHMM TestFile;find . -newer TestFile -exec rm {} \;
0
 

Author Comment

by:pal2k
ID: 35215755
thks, I see this is the best solution.....

-mtime, -ctime, or -atime working in a diff machine , and I can use this machine.

So, now I want to use the fins command as below:
From current dir where ever I am,  for all zone* 1 level sub-dir's, need to find files like *xyz* files only which are 45 mins or less older.
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35215828


find ./zone* -depth 1 - mmin 45 -print > /tmp/find_list
0
 
LVL 8

Assisted Solution

by:point_pleasant
point_pleasant earned 500 total points
ID: 35215848
oops


find ./zone*/xyz* -type f -mmin 45 -print > /tmp/find_list
0
 
LVL 8

Assisted Solution

by:point_pleasant
point_pleasant earned 500 total points
ID: 35215937
the problem with -mtime -ctime or -atime is that they wotk in increments of  1 day and do not take fractional arguements so you cant say -mtime 0.5 for 12 hours ago.  if -mmin works on the other machine i would use that.  on reh hat linux there is also -amin -cmin.  if all that works is the -newer on your solaris you may be stuck with that.  tou could put the code above in the /usr/bin directory and call it from the command line.  kind cheating but.............
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question