- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Find and remove files between two dates
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
Forums
Discussions
Discussions
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
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
03-09-2007 04:51 PM
03-09-2007 04:51 PM
Find and remove files between two dates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2007 09:22 PM
03-09-2007 09:22 PM
Re: Find and remove files between two dates
please tell us your request more exactly:
- all files in a directory?
- all files recursivly under a directory tree?
- should directories an links removed as well?
In general, create two files via the 'touch' command, having timestamps of the seach limits.
Then use the test operators 'nt' and 'ot' of the posix shell or the 'find' option -newer/! -newer to get the requested files.
The man pages of 'test' and 'find' will help you.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2007 09:27 PM
03-09-2007 09:27 PM
Re: Find and remove files between two dates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2007 09:44 PM
03-09-2007 09:44 PM
Re: Find and remove files between two dates
try this:
touch -t 0602100000 /tmp/begin
touch -t 0602122359 /tmp/end
cd /var/cron/messages
for i in *
do
[ -f $i ] || continue
[ $i -nt /tmp/begin -a $i -ot /tmp/end ] && print rm $i
done
Remove the 'print' after your test to drop the file really.
mfG Peter
PS: Since you are new to this forum, I want to put your attention to ist unique point system:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2007 12:31 AM
03-10-2007 12:31 AM
Re: Find and remove files between two dates
Peter's solution is an excellent one if you don't want to recursively descend within a directory. If, on the other hand, you do want to find all candicate files in a directory and its subdirectories, this is another approach:
# touch -t 0602100000 /tmp/begin
# touch -t 0602122359 /tmp/end
# cd /dir
# find . -xdev -type f -newer /tmp/begin -a ! -newer /tmp/end | xargs rm
The '-xdev' prevents crossing mountpoints. The '-f' tells 'find' to look only for files. THe '-newer' and its negation with the "!" bound the criteria for file timestamps (using the last modification or 'mtime'). Piping the output to 'xargs' causes multiple arguments to be supplied to 'rm' at a time, thus spawning as few processes as possible to do the work needed.
Regards!
...JRF...