- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help: newer option in find
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
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
тАО07-30-2008 01:05 AM - last edited on тАО03-28-2013 11:54 PM by Cathy_xu
тАО07-30-2008 01:05 AM - last edited on тАО03-28-2013 11:54 PM by Cathy_xu
Hi,
In a given directory i want to find out the latest file(the file will be of the format filename.YYYYMMDDHHISS), store its time stamp in a file. Next day when i run my script i have to get all the recent files to the time stamp stored in that file. Can this be done using newer option in find. Please suggest any other options if available
Thanks in advance
Moved from HP-UX Technical Documentation to HP-UX > languages
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2008 01:31 AM
тАО07-30-2008 01:31 AM
Re: help: newer option in find
touch -r saved-filename ref_file
Then use find:
find . -newer ref_file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2008 05:00 AM
тАО07-30-2008 05:00 AM
Re: help: newer option in find
Dennis' solution is fine, except I would urge you to add the '-xdev' and '-type f' switches and arguments:
# find -xdev . -type f -newer ref_file
The '-xdev' prevents crossing mountpoints. This becomes particularly important if you want to search '/' where you might want to include directories like '/etc' and '/sbin' but not visit directories like '/var' and '/opt'.
Specifying '-type f' limits selection to only *files* and not directories.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2008 05:12 AM
тАО07-30-2008 05:12 AM
Re: help: newer option in find
find /directory_path -xdev -type f -newer "file_name" -exec ls -lrt {} \;
where file_name the latest time stamp file you recorded last.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2008 08:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2008 03:08 AM
тАО07-31-2008 03:08 AM
Re: help: newer option in find
Thanks for the response.
Iam afraid i cannot touch the files as they are in production. Please let me know if i can save the time stamp in some temporary file and make use of that time stamp in finding the newer file. Also if there are files with same time stamp, will they be considered when newer is useD?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2008 03:32 AM
тАО07-31-2008 03:32 AM
Re: help: newer option in find
Noted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2008 04:08 AM
тАО07-31-2008 04:08 AM
Re: help: newer option in find
> Iam afraid i cannot touch the files as they are in production. Please let me know if i can save the time stamp in some temporary file and make use of that time stamp in finding the newer file.
You are not altering the data or the metadata (ownership, permissions or timestamps) of any production files, unless you consider updating the lastaccess timestamp of directories as they are searched (which would happen anytime someone did an 'ls' anyway!).
You simply create a reference file in a directory of your choice:
# touch -mt 200807310000 /var/tmp/myref
# find /apps -xdev -type f -newer /var/tmp/myref
Another variation as Dennis suggested is to create your reference file with the same timestamp as a production one. Here again, the production file is not altered in any way:
# touch -r /etc/hosts /var/tmp/myref
...which creates '/var/tmp/myref' with a modification timestamp ('mtime') equal to that of '/etc/hosts'.
> Also if there are files with same time stamp, will they be considered when newer is useD?
If the 'mtime' of a file is exactly equal to the second, no. "Newer" means newer.
Notice that the 'touch' can include seconds of time:
# touch -mt 200807310001.00 /var/tmp/myref
You can find files within ranges of time by doing:
# touch -mt 200807010000.00 /var/tmp/myref1
# touch -mt 200807312359.59 /var/tmp/myref2
# find /path -xdev -type f -newer /var/tmp/myref1 -a ! -newer /var/tmp/myref2 -exec ls -l {} +
This finds files in '/path' (your choice) that have been modified sometime during the month of July 2008. The '!' means "not" while the '-a' means "and".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2008 12:32 AM
тАО08-04-2008 12:32 AM
Re: help: newer option in find
Thanks for your inputs. Iam using the command as follows
find . -xdev -type f -newer *.$tim
where tim like 20080216110333
Iam storing that tim variable in a file and using that in my query. My files are of the format ?????.TN??????.ABC.200808040930. But if two files have the same time stamp , iam facing an error
find: missing conjunction
Is there any way to over come this error?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2008 12:40 AM
тАО08-04-2008 12:40 AM
Re: help: newer option in find
Instead of storing a tim variable, store the complete file name. Or as I said, create a reference file, then you don't need to store anything.
>But if two files have the same time stamp, I am facing an error
>Is there any way to overcome this error?
Try using head(1) to pick the first:
find . -xdev -type f -newer $(ls *.$tim | head -1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2008 03:58 AM
тАО08-04-2008 03:58 AM
Re: help: newer option in find
> Iam storing that tim variable in a file and using that in my query
This isn't going to work the way you are doing it. Re-read my last post. You need to create a dummy "reference" file (with 'touch') to supply as the argument to '-newer' in your 'find'. When you do an 'ls -l' of the reference file, its timestamp (not its name!) should represent the time and date of interest.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2008 06:37 AM
тАО08-21-2008 06:37 AM