Solved

unix find command with timestamp

Posted on 2011-03-15
16
890 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 …
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…
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…

623 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