Solved

unix find command with timestamp

Posted on 2011-03-15
16
855 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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