Solved

unix find command with timestamp

Posted on 2011-03-15
16
868 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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Backing Up Ipset 9 124
Remove Settings button from start menu (Windows 10) 1 309
how to pick files up from ftp via script 8 53
Shell Script on AIX 7 142
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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 …
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…

685 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