Solved

unix find command with timestamp

Posted on 2011-03-15
16
852 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now