- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to check if a file is more than 1 week ol...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
тАО06-28-2005 03:28 PM
тАО06-28-2005 03:28 PM
Is there a one line command to check if the file is 1 week old or more?
Maximum points to all correct replies.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 03:46 PM
тАО06-28-2005 03:46 PM
Re: how to check if a file is more than 1 week old?
use the find command:
# find /etc -mtime +6 -exec ls -ld {} \;
using /etc directory to find which file/s is modified 7 days or more.
regards.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 03:46 PM
тАО06-28-2005 03:46 PM
Re: how to check if a file is more than 1 week old?
You can use the find command:
# find /
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 03:49 PM
тАО06-28-2005 03:49 PM
Re: how to check if a file is more than 1 week old?
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 03:51 PM
тАО06-28-2005 03:51 PM
SolutionNow if you are willing to change you question to something "has the file neen modified in the last 7 days?" then it becomes possible using the attached Perl script:
typeset FNAME="myfile"
typeset -i PERIOD=604800
fileage.pl -m -s ${PERIOD} "${FNAME}"
typeset -i STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "${FNAME} has not been in ${PERIOD} seconds"
else
if [[ ${STAT} -eq 1 ]]
then
echo "${FNAME} has been modified with the last ${PERIOD} seconds"
else
echo "Command failed; status ${STAT}" > &2
fi
fi
Here's the Perl script, fileage.pl. Invoke as fileage.pl for full usage.
- Tags:
- fileage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 06:51 PM
тАО06-28-2005 06:51 PM
Re: how to check if a file is more than 1 week old?
find /tmp \( -mtime +7 -o -atime +7 -o -ctime +7 \) -type f
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 07:23 PM
тАО06-28-2005 07:23 PM
Re: how to check if a file is more than 1 week old?
because you have to distinguish between
the file's last modification time (mtime),
access time (atime), and inode change time (ctime), and all of them can be changed at any time.
You get these three times in epoch secs through a stat() syscall.
I think the easiest interface to stat() is through Perl.
Apart from stat() Perl also offers a nice file test feature through -M, -A, -C that return the days of the respective last change since the (Perl) script started.
This relieves you from doing subtractions and conversions from epoch secs to days youself.
Here's a wee example
$ date
Wed Jun 29 09:03:18 METDST 2005
$ touch -m -t 06211200 /tmp/tref
$ ll /tmp/tref
-rw-r--r-- 1 saz users 0 Jun 21 12:00 /tmp/tref
$ perl -le 'print -M shift' /tmp/tref
7.87875
$ perl -le 'print -A shift' /tmp/tref
0.000844907407407407
$ perl -le 'print -C shift' /tmp/tref
0.000960648148148148
$ perl -le 'printf"atime: %d\nmtime: %d\nctime: %d\n",(stat shift)[8..10]' /tmp/tref
atime: 1120028679
mtime: 1119348000
ctime: 1120028679
$ perl -le 'print scalar localtime 1119348000'
Tue Jun 21 12:00:00 2005
- Tags:
- Perl