HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- File creation/modification time
Operating System - Linux
1828221
Members
2130
Online
109975
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2008 03:46 AM
03-10-2008 03:46 AM
I want to check a file name, whether it is created/modified within last x mins or not.
How to do it?
I must take into consideration about leap year, year changed etc.
Rgds
-NKG-
How to do it?
I must take into consideration about leap year, year changed etc.
Rgds
-NKG-
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2008 04:01 AM
03-10-2008 04:01 AM
Re: File creation/modification time
Use "touch" to create a reference file with the appropriate date/time value, then use the find command with the "-newer" option to compare if the files are more recent than your reference file.
Do a man on touch and a man on find for specifics.
Pete
Pete
Do a man on touch and a man on find for specifics.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2008 04:02 AM
03-10-2008 04:02 AM
Re: File creation/modification time
Hi:
There is no such thing in UNIX as a "creation" timestamp. The last modification ('mtime') is coincidently a creation at the instance that a file is first created. Thereafter it is updated any time the file contents or offset change.
That said, you can use 'find' to look for files meeting your criteria. The '-mtime' argument is a 24-hour increment. The '-newer' argument used with a "reference file" and 'touch' allows measurement from a preset point.
Perl provides the easy way to compute a file age in units of seconds:
# perl -le 'print "OK" if -e $ARGV[0] && -M $ARGV[0] > (3600/86400)' file
...would print "OK" if the file (name) passed as an argument to the Perl script were older than 3600/86400 of a day or older than 1-hour. Granularity is in seconds so one-second would be 1/86400 of a day.
Regards!
...JRF...
There is no such thing in UNIX as a "creation" timestamp. The last modification ('mtime') is coincidently a creation at the instance that a file is first created. Thereafter it is updated any time the file contents or offset change.
That said, you can use 'find' to look for files meeting your criteria. The '-mtime' argument is a 24-hour increment. The '-newer' argument used with a "reference file" and 'touch' allows measurement from a preset point.
Perl provides the easy way to compute a file age in units of seconds:
# perl -le 'print "OK" if -e $ARGV[0] && -M $ARGV[0] > (3600/86400)' file
...would print "OK" if the file (name) passed as an argument to the Perl script were older than 3600/86400 of a day or older than 1-hour. Granularity is in seconds so one-second would be 1/86400 of a day.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2008 04:08 AM
03-10-2008 04:08 AM
Solution
Standard smarty pants line: Unix does not maintain a 'created time' for files.
Many ways to solve this
touch + find ... -newer is always handy.
I use perl for just about everything.
It has a -M file function returning the Modified age for a file in days
In a verbose example:
$ perl -le '$file = shift; $_ = ( 5/(24*60) < -M $file) ? "old" : "new"; print'
Many ways to solve this
touch + find ... -newer is always handy.
I use perl for just about everything.
It has a -M file function returning the Modified age for a file in days
In a verbose example:
$ perl -le '$file = shift; $_ = ( 5/(24*60) < -M $file) ? "old" : "new"; print'
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP