- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to rm files by extension and year?
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
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
09-15-2003 10:26 AM
09-15-2003 10:26 AM
The files I want to remove have an extension of .OLD, but I want to rm the ones prior to 2003 *only*.
I know it's possible, but I don't have scripting experience.
Thanks-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 10:29 AM
09-15-2003 10:29 AM
Solutionfind /dir -name '*.OLD' -mtime +285 |xargs rm
That should search from the starting directory "/dir" down, finding all files with a name ending in .OLD that haven't been touched since 285 days ago (roughly the beginning of the year, by my calculations), and removing them.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 10:31 AM
09-15-2003 10:31 AM
Re: How to rm files by extension and year?
It will remove all *.OLD files created before 01/01/03.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 10:38 AM
09-15-2003 10:38 AM
Re: How to rm files by extension and year?
I like Vitek's solution much better - mostly because my manual date computation was off by about a month.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 10:38 AM
09-15-2003 10:38 AM
Re: How to rm files by extension and year?
Thanks so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 10:39 AM
09-15-2003 10:39 AM
Re: How to rm files by extension and year?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 10:42 AM
09-15-2003 10:42 AM
Re: How to rm files by extension and year?
Use the find command to find these & delete them.
First use the touch command to create a file dated midnight 01/01/03 as follows:
touch -t 200301010000 /tmp/pre2003
Then use the find command using the and operator to find & remove the *.OLD files older than this.
find / \(-name "*.OLD" -a ! -newer /tmp/pre2003 \) -exec rm {} \;
HINT - Use ll in place of rm *first* to list the files before using rm JUST TO BE SURE.
HTH,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 11:42 AM
09-15-2003 11:42 AM
Re: How to rm files by extension and year?
find . -name "*.OLD" -mtime +`date +%j` | xargs -i rm {}
It will remove all *.OLD files created before 01/01/03.
Could someone explain this. I use the find and mtime option but the +`date +%j` I don't
understand. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 11:42 AM
09-15-2003 11:42 AM
Re: How to rm files by extension and year?
find . -name "*.OLD" -mtime +`date +%j` | xargs -i rm {}
It will remove all *.OLD files created before 01/01/03.
Could someone explain this. I use the find and mtime option but the +`date +%j` I don't
understand. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 11:53 AM
09-15-2003 11:53 AM
Re: How to rm files by extension and year?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2003 11:53 AM
09-15-2003 11:53 AM
Re: How to rm files by extension and year?
%j is the day of the year in a 3 digit number.
So Vitek is fuuneling the number of days to go *back* to the -mtime paramter using the command
date +%j
Try this command
date +%j - You should get 258 today & 259 tomorrow.
HTH,
Jeff